Grep your Rails models to identify structure

I recently noticed that I use search a lot on the command line, especially when working Rails apps. It has helped me speed up a little bit.

In the following examples I use ag. You could use grep, ack or even some feature/plugin in your text editor.

List all model associations

ag "has_many|belongs_to" app/models

List Cucumber step definitions

ag "Given|Then|When" features/step_definitions

Search for a specific Cucumber step definition

Do pattern searches with your search command/tool in order to find specific step defs.

ag "When.+user" features/step_definitions

The above command searches for a “When” step def with the word “user” in the line.