Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use public_send in value_for_collection#33547

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
matthewd merged 5 commits intorails:masterfromAna06:patch-1
Aug 22, 2018
Merged

Conversation

@Ana06
Copy link
Contributor

@Ana06Ana06 commentedAug 7, 2018
edited
Loading

Deprecate use of private methods in view's helpers. We should start callingpublic_send invalue_for_collection instead ofsend to void exposing private methods in view's helpers.:bowtie:

Fixes#33546

gshaw reacted with heart emoji
@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@georgeclaghorn (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 usingCode 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 seethe contribution instructions for more information.

Avoid exposing private methods in view's helpers.Fixesrails#33546
@matthewd
Copy link
Member

Hi!

I agree we should change this. (And the othersend I spotted a few lines above.)

If it's worth fixing, it's worth keeping fixed, so we should add a test too.

My big question-mark, however, is whether we need a deprecation. Much aspublic_send is a far more sensible choice, it seems likelysomeone is currently, perhaps inadvertently, relying on the fact we call private methods.@rafaelfranca?

@rafaelfranca
Copy link
Member

Agree. It is safer if we deprecate it.

@Ana06
Copy link
ContributorAuthor

@matthewd

And the other send I spotted a few lines above.

👍

If it's worth fixing, it's worth keeping fixed, so we should add a test too.

I'll add it 😉

@matthewd@rafaelfranca regarding the deprecation, I guess you mean showing a message in case that the method used is private and not to deprecate the method itself, right?

@matthewd
Copy link
Member

Right. I think we'd do it something like this:

beginitem.public_send(value)rescueNoMethodErrorifitem.respond_to?(value,true) && !item.respond_to?(value)ActiveSupport::Deprecation"Hey don't do that"item.send(value)elseraiseendend
Ana06 reacted with thumbs up emoji

Avoid exposing private methods in view's helpers. However, as`extract_values_from_collection` is only called from`options_from_collection_for_select` where `value_for_collection` ispreviously called, this case was already covered. The change makesanyway sense for consistency and in case the code changes in thefuture.
@Ana06Ana06force-pushed thepatch-1 branch 2 times, most recently from1fb8b26 toca77aabCompareAugust 8, 2018 08:46
@Ana06
Copy link
ContributorAuthor

I think at least0c62e14 should be rebased into87b6e6a, but I left it like that following@rails-bot instructions:

If any changes to this PR are deemed necessary, please add them as extra commits.

Instead of dropping it completely in case someone is relying (probablyinadvertenly) on it.
@Ana06Ana06force-pushed thepatch-1 branch 3 times, most recently from6adcd14 todef801aCompareAugust 8, 2018 16:03
Test that using private methods in `options_from_collection_for_select`is deprecated.Make the unused `secret` paramether in the `Post` Struct private to useit in the test.
@Ana06
Copy link
ContributorAuthor

Ana06 commentedAug 8, 2018
edited
Loading

@matthewd@rafaelfranca I think the changes are addressed, please take a look. 🙏 Do we need to test other view's helpers or is it enough with testingoptions_from_collection_for_select? 🤔

@georgeclaghorn
Copy link
Contributor

r?@matthewd

@Ana06
Copy link
ContributorAuthor

@matthewd something else to change? 🤔

@matthewdmatthewd merged commit0853cdf intorails:masterAug 22, 2018
matthewd added a commit that referenced this pull requestAug 22, 2018
Use public_send in value_for_collection
@matthewd
Copy link
Member

Nope, this is great, thanks! ❤️

I made a few of tweaks in the merge commit, FYI:047a893 (changelog formatting, and I added the name of the called private method to the deprecation message)

@Ana06
Copy link
ContributorAuthor

Ana06 commentedAug 22, 2018
edited
Loading

@matthewd

I made a few of tweaks in the merge commit, FYI:047a893 (changelog formatting, and I added the name of the called private method to the deprecation message)

I could have made the changes, now my name is not in the commit anymore 😭 😭 😭

@matthewd
Copy link
Member

@Ana06 all your commits are in there:https://contributors.rubyonrails.org/contributors/ana-maria-martinez-gomez/commits (Oops.. if I'd seen there were so many I should've gotten you to squash. Oh well. 🤷🏻‍♂️)

@Ana06
Copy link
ContributorAuthor

Ana06 commentedAug 22, 2018
edited
Loading

@matthewd

@Ana06 all your commits are in there:https://contributors.rubyonrails.org/contributors/ana-maria-martinez-gomez/commits (Oops.. if I'd seen there were so many I should've gotten you to squash. Oh well. 🤷🏻‍♂️)

you are right, sorry 🙈 I though you squashed the commits, because they needed to be squashed and I didn't see them in the commits history. It seems it is a different way to merge things (withour rebasing) and I didn't see them 👀

Thanks for merging it 😉

@matthewd
Copy link
Member

No worries, thanks for the work! (It's an ordinary merge, but that means your commits are further down the list [currently on page 5 by my count], based on their commit date, even though they only just hit master.)

@Ana06
Copy link
ContributorAuthor

Ana06 commentedAug 28, 2018
edited
Loading

@matthewd@rafaelfranca I spoke about this PR in my talk at EuRuKo (in front of around ~550 people), maybe you want to watch it:https://youtu.be/jUc8InwoA-E?t=2m54s 😉

The part where I speak about this is almost as the end, but I am not sure if it is possible to follow without watching the whole talk. 🤔 It is anyway not that long! only 25 minutes 😄

matthewd reacted with hooray emoji

@Ana06Ana06 deleted the patch-1 branchApril 30, 2019 14:31
suketa added a commit to suketa/rails_sandbox that referenced this pull requestMay 15, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

@matthewdmatthewd

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

5 participants

@Ana06@rails-bot@matthewd@rafaelfranca@georgeclaghorn

[8]ページ先頭

©2009-2025 Movatter.jp