Skip to content

Conversation

@westonganger
Copy link
Contributor

Solves #13

@7even
Copy link
Owner

7even commented Feb 7, 2019

Sorry I didn't mention this earlier but I don't think we need another means of configuration since the gem already has one. Could you please just add the ignored_models option there?

@westonganger
Copy link
Contributor Author

Jeez that sucks. I guess I didn't read the readme well enough because there is no configurator example shown.

@westonganger westonganger changed the title Add Support for Ignoring Models using .annotate_ignore Add Support for Ignoring Models with config.ignored_models Feb 7, 2019
@westonganger
Copy link
Contributor Author

I've added specs however I cannot test ignored_models during annotation as the test suite doesn't seem to support the implemented method for translating the file name to class. Likely you would need to add a full Rails app to the test suite.

Copy link
Owner

@7even 7even left a comment

Choose a reason for hiding this comment

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

It seems like you are testing in the wrong place. You changed the Annotate.models method but you are testing it in the specs for Annotate::File which doesn't call it.

Actually it's the reverse - Annotate.annotate uses Annotate.models to get a list of models to annotate and then calls Annotate::File#annotate_with on each of them.

I would suggest adding a test for Annotate.models to check that it doesn't include the ignored models.


class User < ActiveRecord::Base
### Define User constant
end
Copy link
Owner

Choose a reason for hiding this comment

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

Is this being used anywhere?

# config.yard = false
#
# # Define any models to be skipped by Annotate
# config.ignored_models = [SomeIgnoredModel, AnotherIgnoredModel]
Copy link
Owner

Choose a reason for hiding this comment

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

I see a potential problem here: AFAIK rails runs initializers before loading the application code so referring to the model classes as constants here will either fail or autoload them, possibly before other initializers are fired (and this doesn't sound good to me).

What if instead of class constants themselves we will use their names as strings? Like %w[SomeIgnoredModel AnotherIgnoredModel]. What do you think?


private

Copy link
Owner

Choose a reason for hiding this comment

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

I prefer to add empty lines only before public/protected/private keywords, not after them; please don't change it.

def configurator
@configurator ||= Configurator.new
end

Copy link
Owner

Choose a reason for hiding this comment

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

This empy line is redundant.


private

Copy link
Owner

Choose a reason for hiding this comment

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

And here.

@yard = false
@ignored_models = []
end

Copy link
Owner

Choose a reason for hiding this comment

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

And here.

class User < ActiveRecord::Base
has_many :posts
end
Copy link
Owner

Choose a reason for hiding this comment

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

This is not the expected result here as the ignored file will not be touched at all - the gem won't erase the old annotation. This is what should be expected.

Copy link
Owner

Choose a reason for hiding this comment

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

But since this is a wrong place to test ignored_models you can just delete this.

@westonganger
Copy link
Contributor Author

I have some other more important tasks on the go right now. Do you have any interest in picking up this PR and finishing the specs for it?

@7even
Copy link
Owner

7even commented Feb 12, 2019

@westonganger currently I can't, sorry. Maybe in a few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants