From c0c1441144aa5e477b3419b033e43c94adf7cc0c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 25 Feb 2019 14:21:14 -0800 Subject: Convert `variant` to a keyword arg --- actionview/lib/action_view/template.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index cc5e0cbb4f..3c25a86b79 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -127,7 +127,7 @@ module ActionView attr_reader :source, :identifier, :handler, :original_encoding, :updated_at attr_reader :variable, :format - def initialize(source, identifier, handler, format: nil, **details) + def initialize(source, identifier, handler, format: nil, variant: nil, **details) unless format ActiveSupport::Deprecation.warn "ActionView::Template#initialize requires a format parameter" format = :html @@ -149,7 +149,7 @@ module ActionView @updated_at = details[:updated_at] || Time.now @format = format - @variants = [details[:variant]] + @variants = [variant] @compile_mutex = Mutex.new end -- cgit v1.2.3 From bcf49299ff3afcb08ba5e155cedeb62a8b79f1fa Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 25 Feb 2019 14:25:43 -0800 Subject: Remove potential `variants` mutation in `decorate` Even if the template is constructed with a `nil` variant, the array it constructs will never be `empty?`: https://github.com/rails/rails/blob/56b030605b4d968077a4ddb96b4ab619e75fb999/actionview/lib/action_view/template.rb#L152 We get an array that is `[nil]`, which is not empty, so this conditional is never true. --- actionview/lib/action_view/template/resolver.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index 220794e443..6f0bf4187e 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -196,7 +196,6 @@ module ActionView cached = nil templates.each do |t| t.locals = locals - t.variants = details[:variants] || [] if t.variants.empty? t.virtual_path ||= (cached ||= build_path(*path_info)) end end -- cgit v1.2.3 From da8cb4fa3d9bc7d7a801578393b0cca37538c108 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 25 Feb 2019 14:31:03 -0800 Subject: Change `variants` to `variant` Templates only have one variant, so we should not store it in an array. This commit converts `variants` to `variant` and deprecates the plural accessor --- actionview/lib/action_view/file_template.rb | 4 ++-- actionview/lib/action_view/template.rb | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/actionview/lib/action_view/file_template.rb b/actionview/lib/action_view/file_template.rb index 43206f02e5..cdc077a01a 100644 --- a/actionview/lib/action_view/file_template.rb +++ b/actionview/lib/action_view/file_template.rb @@ -22,11 +22,11 @@ module ActionView # to ensure that references to the template object can be marshalled as well. This means forgoing # the marshalling of the compiler mutex and instantiating that again on unmarshalling. def marshal_dump # :nodoc: - [ @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants ] + [ @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variant ] end def marshal_load(array) # :nodoc: - @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants = *array + @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variant = *array @compile_mutex = Mutex.new end end diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 3c25a86b79..faccbc5a74 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -122,10 +122,10 @@ module ActionView extend Template::Handlers - attr_accessor :locals, :variants, :virtual_path + attr_accessor :locals, :virtual_path attr_reader :source, :identifier, :handler, :original_encoding, :updated_at - attr_reader :variable, :format + attr_reader :variable, :format, :variant def initialize(source, identifier, handler, format: nil, variant: nil, **details) unless format @@ -149,15 +149,14 @@ module ActionView @updated_at = details[:updated_at] || Time.now @format = format - @variants = [variant] + @variant = variant @compile_mutex = Mutex.new end - def formats=(_) - end - deprecate :formats= - + deprecate def formats=(_); end deprecate def formats; Array(format); end + deprecate def variants=(_); end + deprecate def variants; [variant]; end # Returns whether the underlying handler supports streaming. If so, # a streaming buffer *may* be passed when it starts rendering. @@ -258,11 +257,11 @@ module ActionView # to ensure that references to the template object can be marshalled as well. This means forgoing # the marshalling of the compiler mutex and instantiating that again on unmarshalling. def marshal_dump # :nodoc: - [ @source, @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants ] + [ @source, @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variant ] end def marshal_load(array) # :nodoc: - @source, @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variants = *array + @source, @identifier, @handler, @compiled, @original_encoding, @locals, @virtual_path, @updated_at, @format, @variant = *array @compile_mutex = Mutex.new end -- cgit v1.2.3