diff options
author | Ana María Martínez Gómez <ammartinez@suse.de> | 2018-08-08 10:35:03 +0200 |
---|---|---|
committer | Ana María Martínez Gómez <ammartinez@suse.de> | 2018-08-08 11:47:11 +0200 |
commit | 4ca9fa11f9a9b5604371f260515c28a0f29cd921 (patch) | |
tree | 3e990e56c6a40383b77bfc967e0e11aa1facc8c4 /actionview/lib/action_view | |
parent | 0c62e141a3fc9b2d00935bb99d2d5f465e1a4fb4 (diff) | |
download | rails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.tar.gz rails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.tar.bz2 rails-4ca9fa11f9a9b5604371f260515c28a0f29cd921.zip |
Deprecate use of private methods in view's helpers
Instead of dropping it completely in case someone is relying (probably
inadvertenly) on it.
Diffstat (limited to 'actionview/lib/action_view')
-rw-r--r-- | actionview/lib/action_view/helpers/form_options_helper.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb index 0fd68b66d4..2ecba2e337 100644 --- a/actionview/lib/action_view/helpers/form_options_helper.rb +++ b/actionview/lib/action_view/helpers/form_options_helper.rb @@ -794,7 +794,7 @@ module ActionView def extract_values_from_collection(collection, value_method, selected) if selected.is_a?(Proc) collection.map do |element| - element.public_send(value_method) if selected.call(element) + public_or_deprecated_send(element, value_method) if selected.call(element) end.compact else selected @@ -802,7 +802,17 @@ module ActionView end def value_for_collection(item, value) - value.respond_to?(:call) ? value.call(item) : item.public_send(value) + value.respond_to?(:call) ? value.call(item) : public_or_deprecated_send(item, value) + end + + def public_or_deprecated_send(item, value) + begin + item.public_send(value) + rescue NoMethodError + raise unless item.respond_to?(value, true) && !item.respond_to?(value) + ActiveSupport::Deprecation.warn "Using private methods in view's helpers is deprecated" + item.send(value) + end end def prompt_text(prompt) |