Skip to content

Added ActionController::Parameters.each_value methods#33979

Merged
rafaelfranca merged 1 commit intorails:masterfrom
lzap:master
Sep 27, 2018
Merged

Added ActionController::Parameters.each_value methods#33979
rafaelfranca merged 1 commit intorails:masterfrom
lzap:master

Conversation

@lzap
Copy link
Contributor

@lzap lzap commented Sep 25, 2018

Although Parameters class is far from implementing Hash and it's obvious that
it's not primarly goal to achieve it, having the two convinient methods for
iterating through parameters makes it more quacking like Hash:

  • each_value
  • each_key

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see a left over. To be removed.

Copy link
Member

Choose a reason for hiding this comment

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

I'm confused. Do you mean you need to add this back or this was left over in a previous PR? It looks like from the example below that the keys are strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I mean, I am going to remove this hunk in the next rebase. Let's do this.

@rafaelfranca
Copy link
Member

We don't want to make Parameters support all Hash values. I'm fine with each keys but each values will skip the parameters protection that we want to enforce. If you want to use those method please transform the parameters in hash using to_h.

@rafaelfranca
Copy link
Member

Although we already have to_pair. Let's add those methods but delegate each_pair and each_value to to_h. If you are calling those methods in a un-permitted Parameter instance we should raise.

@rafaelfranca rafaelfranca reopened this Sep 25, 2018
@rafaelfranca
Copy link
Member

Forget about that, changing behaviour of each to yield hashes will be a breaking change. each_key is already supported. Let's change this PR to only implement each_value.

@lzap
Copy link
Contributor Author

lzap commented Sep 27, 2018

Rebased: new implementation of only each_value, tests for both each_value and each_key. For the latter I am asserting String type, not sure what else I can assert.

@lzap lzap changed the title Added ActionController::Parameters.each_value/key methods Added ActionController::Parameters.each_value methods Sep 27, 2018
@rafaelfranca rafaelfranca merged commit 140ec68 into rails:master Sep 27, 2018
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Oct 15, 2018
`each_value` should yield with "value" of the params instead of "value" as an array.
Related to rails#33979
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Oct 15, 2018
kamipo pushed a commit that referenced this pull request Oct 15, 2018
… to this method (#34210)

* Fix `ActionController::Parameters#each_value`

`each_value` should yield with "value" of the params instead of "value" as an array.
Related to #33979

* Add changelog entry about `ActionController::Parameters#each_value`.

Follow up #33979
suketa added a commit to suketa/rails_sandbox that referenced this pull request Jun 9, 2019
Added ActionController::Parameters.each_value methods
rails/rails#33979
suketa added a commit to suketa/rails_sandbox that referenced this pull request Jun 9, 2019
Added ActionController::Parameters.each_value methods
rails/rails#33979
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.

4 participants