From 0da775846aa186238ad1813ed414ae508ae0f706 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 15 Mar 2014 06:55:14 -0700 Subject: Clarify AV::Digestor.digest method signature docs and deprecation warning --- actionview/lib/action_view/digestor.rb | 43 +++++++++++++++---------------- actionview/test/template/digestor_test.rb | 4 +-- 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'actionview') 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 # * finder - An instance of ActionView::LookupContext # * dependencies - An array of dependent views # * partial - 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 -- cgit v1.2.3