Skip to content

Commit

Permalink
Clarify AV::Digestor.digest method signature docs and deprecation war…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
jeremy committed Mar 15, 2014
1 parent 178e261 commit 10ab2b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
43 changes: 21 additions & 22 deletions actionview/lib/action_view/digestor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class << self
# * <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])
Expand All @@ -33,20 +33,22 @@ def digest(*args)
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

Expand Down Expand Up @@ -75,13 +77,10 @@ def compute_and_store_digest(cache_key, options) # called under @@digest_monitor

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
Expand Down
4 changes: 2 additions & 2 deletions actionview/test/template/digestor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def test_digest_cache_cleanup_with_recursion_and_template_caching_off
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
Expand Down

0 comments on commit 10ab2b0

Please sign in to comment.