Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for additional file patterns #633

Merged
merged 2 commits into from
Jul 10, 2019

Conversation

ryanwjackson
Copy link
Contributor

This PR adds an option named additional_file_patterns. You can specify custom path patterns (including globs) that the gem will use to annotate.

For example, I used it like this on a project:

Annotate.set_defaults(
      'additional_file_patterns' => [
        File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb'),
        File.join(Rails.application.root, 'spec/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')
      ],
      ...
)

This makes it possible to have files nested under a directory which corresponds to the model.

I believe this fixes #594.

case pattern_type
when 'test' then test_files(root_directory)
when 'fixture' then fixture_files(root_directory)
when 'scaffold' then scaffold_files(root_directory)
when 'factory' then factory_files(root_directory)
when 'serializer' then serialize_files(root_directory)
when 'additional_file_patterns'
[options[:additional_file_patterns] || []].flatten
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate what's going on here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return the config setting additional_file_patterns, which is a list of files and/or globs. This allows the gem to infer models based on file structure or naming and annotate additional files.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should've been more specific - I'm curious about:

[options[:additional_file_patterns] || []].flatten

Is there any special reason behind it? Couldn't it also be:

options[:additional_file_patterns] || []

@ryanwjackson
Copy link
Contributor Author

ryanwjackson commented Jul 10, 2019 via email

@drwl
Copy link
Collaborator

drwl commented Jul 10, 2019

Oh no problem, I didn't consider that possibility. So right now it looks like this can be used by invoking Annotate in code. Do you think this should and could be invoked using command line arguments? This would be covered in bin/annotate

@drwl
Copy link
Collaborator

drwl commented Jul 10, 2019

Also nice to see a fellow xooyalan! 👋

@ryanwjackson
Copy link
Contributor Author

@drwl I created #636 for the CLI arg.

@drwl
Copy link
Collaborator

drwl commented Jul 10, 2019

Looks good thanks for adding tests and adding it to the CLI.

@drwl drwl added the feature label Jul 10, 2019
@drwl drwl added this to the v3.0.0 milestone Jul 10, 2019
@drwl drwl merged commit f95913b into ctran:develop Jul 10, 2019
drwl pushed a commit that referenced this pull request Aug 6, 2019
Adds option for additional file patterns (implemented in #633) in the CLI.
drwl pushed a commit that referenced this pull request Aug 8, 2019
Add better documentation for new option for additional file patterns. Implemented in #633 and #636.
peterfication pushed a commit to store2be/annotate_models that referenced this pull request Jan 20, 2020
This PR adds an option named `additional_file_patterns`.  You can specify custom path patterns (including globs) that the gem will use to annotate.

For example, I used it like this on a project:

```ruby
Annotate.set_defaults(
      'additional_file_patterns' => [
        File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb'),
        File.join(Rails.application.root, 'spec/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')
      ],
      ...
)
```

This makes it possible to have files nested under a directory which corresponds to the model.

I believe this fixes ctran#594.
peterfication pushed a commit to store2be/annotate_models that referenced this pull request Jan 20, 2020
Adds option for additional file patterns (implemented in ctran#633) in the CLI.
peterfication pushed a commit to store2be/annotate_models that referenced this pull request Jan 20, 2020
Add better documentation for new option for additional file patterns. Implemented in ctran#633 and ctran#636.
vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
This PR adds an option named `additional_file_patterns`.  You can specify custom path patterns (including globs) that the gem will use to annotate.

For example, I used it like this on a project:

```ruby
Annotate.set_defaults(
      'additional_file_patterns' => [
        File.join(Rails.application.root, 'app/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb'),
        File.join(Rails.application.root, 'spec/lib/forms/%PLURALIZED_MODEL_NAME%/**/*.rb')
      ],
      ...
)
```

This makes it possible to have files nested under a directory which corresponds to the model.

I believe this fixes ctran#594.
vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
Adds option for additional file patterns (implemented in ctran#633) in the CLI.
vfonic pushed a commit to vfonic/annotate_models that referenced this pull request May 8, 2020
Add better documentation for new option for additional file patterns. Implemented in ctran#633 and ctran#636.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotate arbitrary files using a file matcher?
2 participants