aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorJeremy Kemper <jeremykemper@gmail.com>2014-03-15 06:55:14 -0700
committerJeremy Kemper <jeremykemper@gmail.com>2014-03-15 06:55:14 -0700
commit0da775846aa186238ad1813ed414ae508ae0f706 (patch)
treeed6a230c7601f67e3a4594e46175b1e2a928010e /actionview
parent7a5601c432d3906cc6ab853b3316e76a162f75d1 (diff)
downloadrails-0da775846aa186238ad1813ed414ae508ae0f706.tar.gz
rails-0da775846aa186238ad1813ed414ae508ae0f706.tar.bz2
rails-0da775846aa186238ad1813ed414ae508ae0f706.zip
Clarify AV::Digestor.digest method signature docs and deprecation warning
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/digestor.rb43
-rw-r--r--actionview/test/template/digestor_test.rb4
2 files changed, 23 insertions, 24 deletions
diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb
index c302bc15fa..40d493da64 100644
--- a/actionview/lib/action_view/digestor.rb
+++ b/actionview/lib/action_view/digestor.rb
@@ -17,8 +17,8 @@ module ActionView
# * <tt>finder</tt> - An instance of ActionView::LookupContext
# * <tt>dependencies</tt> - An array of dependent views
# * <tt>partial</tt> - Specifies whether the template is a partial
- def digest(*args)
- options = _options_for_digest(*args)
+ def digest(options_or_deprecated_name, *deprecated_args)
+ options = _options_for_digest(options_or_deprecated_name, *deprecated_args)
details_key = options[:finder].details_key.hash
dependencies = Array.wrap(options[:dependencies])
@@ -33,20 +33,22 @@ module ActionView
end
end
- def _options_for_digest(*args)
- unless args.first.is_a?(Hash)
- ActiveSupport::Deprecation.warn("Arguments to ActionView::Digestor should be provided as a hash. The support for regular arguments will be removed in Rails 5.0 or later")
-
- {
- name: args.first,
- format: args.second,
- finder: args.third,
- }.merge(args.fourth || {})
+ def _options_for_digest(options_or_deprecated_name, *deprecated_args)
+ if !options_or_deprecated_name.is_a?(Hash)
+ ActiveSupport::Deprecation.warn \
+ 'ActionView::Digestor.digest changed its method signature from ' \
+ '#digest(name, format, finder, options) to #digest(options), ' \
+ 'with options now including :name, :format, :finder, and ' \
+ ':variant. Please update your code to pass a Hash argument. ' \
+ 'Support for the old method signature will be removed in Rails 5.0.'
+
+ _options_for_digest (deprecated_args[2] || {}).merge \
+ name: options_or_deprecated_name,
+ format: deprecated_args[0],
+ finder: deprecated_args[1]
else
- options = args.first
- options.assert_valid_keys(:name, :format, :variant, :finder, :dependencies, :partial)
-
- options
+ options_or_deprecated_name.assert_valid_keys(:name, :format, :variant, :finder, :dependencies, :partial)
+ options_or_deprecated_name
end
end
@@ -75,13 +77,10 @@ module ActionView
attr_reader :name, :format, :variant, :finder, :options
- def initialize(*args)
- @options = self.class._options_for_digest(*args)
-
- @name = @options.delete(:name)
- @format = @options.delete(:format)
- @variant = @options.delete(:variant)
- @finder = @options.delete(:finder)
+ def initialize(options_or_deprecated_name, *deprecated_args)
+ options = self.class._options_for_digest(options_or_deprecated_name, *deprecated_args)
+ @options = options.except(:name, :format, :variant, :finder)
+ @name, @format, @variant, @finder = options.values_at(:name, :format, :variant, :finder)
end
def digest
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb
index 1c47952f54..0cbfd14c94 100644
--- a/actionview/test/template/digestor_test.rb
+++ b/actionview/test/template/digestor_test.rb
@@ -262,8 +262,8 @@ class TemplateDigestorTest < ActionView::TestCase
end
def test_arguments_deprecation
- assert_deprecated(/should be provided as a hash/) { ActionView::Digestor.digest('messages/show', :html, finder) }
- assert_deprecated(/should be provided as a hash/) { ActionView::Digestor.new('messages/show', :html, finder) }
+ assert_deprecated(/will be removed/) { ActionView::Digestor.digest('messages/show', :html, finder) }
+ assert_deprecated(/will be removed/) { ActionView::Digestor.new('messages/show', :html, finder) }
end
private