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

tracking attribute path into options[:attr_path] #139

Merged
merged 1 commit into from
Jul 29, 2015

Conversation

calfzhou
Copy link
Contributor

@calfzhou calfzhou commented Jul 9, 2015

Make Grape::Entity keep tracking of current being exposed attribute's full path into options[:attr_path].

@dblock
Copy link
Member

dblock commented Jul 9, 2015

I really like this, needs a CHANGELOG entry, please.

begin
next unless should_return_attribute?(attribute, opts) && conditions_met?(exposure_options, opts)

partial_output = value_for(attribute, opts)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe construction of partial_output can be refactored into a method?

some refines; new test cases; change log updated
@calfzhou
Copy link
Contributor Author

squashed and rebased to current master.

dblock added a commit that referenced this pull request Jul 29, 2015
tracking attribute path into options[:attr_path]
@dblock dblock merged commit abefb7f into ruby-grape:master Jul 29, 2015
@dblock
Copy link
Member

dblock commented Jul 29, 2015

Merged.

@@ -7,12 +7,12 @@

# Offense count: 8
Metrics/AbcSize:
Max: 51
Max: 53
Copy link
Member

Choose a reason for hiding this comment

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

Metrics should not increase. Why we use RuboCop if we just stab it?

Copy link
Member

Choose a reason for hiding this comment

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

Personally I don't care as much, I think it's a good flag and if it makes sense, I would not make it a barrier.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think the same but I just want to see things before changing .rubocop_todo.yml. There could be something we can suggest to easily fix and if there is not then we suggest to just regenerate .rubocop_todo.yml :)

Copy link
Member

Choose a reason for hiding this comment

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

As features and their correctness are superior to style pedantry, I want to push #160.

I think the reason that people just stab RuboCop offenses is that it runs before RSpec. It prevents maintainers to just see if the feature implemented correctly or not.

Copy link
Member

Choose a reason for hiding this comment

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

I would like to disable this offense in Rubocop, and be able to run --auto-gen-config for everything else. However when you try to do the latter it ignores what's in .rubocop.yml, which defeats the whole purpose.

Feel free to switch it to run after, btw.

@marshall-lee
Copy link
Member

@calfzhou, @dblock

I ported this feature while working on rebasing #151. But I changed your specs because in the new design there's no place for methods like key_for, name_for and (newly introduced) path_for.

Instead of this I implemented an :attr_path exposure option that adds the same possibility:

expose :charactersistics, attr_path: -> (obj, opts) { :character }
expose :need_to_skip, attr_path: -> (obj, opts) { nil }

Maybe it would be useful to also add these possibilities in future:

expose :need_to_skip, attr_path: :character # just constant
expose :need_to_skip, attr_path: nil # just skip

@dblock
Copy link
Member

dblock commented Aug 2, 2015

Thanks @marshall-lee your changes make sense to me.

@calfzhou
Copy link
Contributor Author

calfzhou commented Aug 3, 2015

@marshall-lee 's attr_path exposure is pretty good!

@calfzhou calfzhou deleted the feature/attr-path branch August 7, 2015 12:19
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.

3 participants