Skip to content

Commit 86b3946

Browse files
committed
Optimize options merging
1 parent d4c8827 commit 86b3946

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lib/jbuilder/jbuilder_template.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
require 'active_support/cache'
55

66
class JbuilderTemplate < Jbuilder
7-
class << self
8-
attr_accessor :template_lookup_options
9-
end
10-
11-
self.template_lookup_options = { handlers: [:jbuilder] }
7+
HANDLERS = [:jbuilder].freeze
128

139
def initialize(context, *args)
1410
@context = context
@@ -137,14 +133,14 @@ def set!(name, object = BLANK, *args)
137133
private
138134

139135
def _render_partial_with_options(options)
140-
options.reverse_merge! locals: options.except(:partial, :as, :collection, :cached)
141-
options.reverse_merge! ::JbuilderTemplate.template_lookup_options
136+
options[:locals] ||= options.except(:partial, :as, :collection, :cached)
137+
options[:handlers] ||= ::JbuilderTemplate::HANDLERS
142138
as = options[:as]
143139

144140
if as && options.key?(:collection) && CollectionRenderer.supported?
145141
collection = options.delete(:collection) || []
146142
partial = options.delete(:partial)
147-
options[:locals].merge!(json: self)
143+
options[:locals][:json] = self
148144
collection = EnumerableCompat.new(collection) if collection.respond_to?(:count) && !collection.respond_to?(:size)
149145

150146
if options.has_key?(:layout)
@@ -173,8 +169,8 @@ def _render_partial_with_options(options)
173169
locals = options.delete(:locals)
174170
array! collection do |member|
175171
member_locals = locals.clone
176-
member_locals.merge! collection: collection
177-
member_locals.merge! as => member
172+
member_locals[:collection] = collection
173+
member_locals[as] = member
178174
_render_partial options.merge(locals: member_locals)
179175
end
180176
else
@@ -186,7 +182,7 @@ def _render_partial_with_options(options)
186182
end
187183

188184
def _render_partial(options)
189-
options[:locals].merge! json: self
185+
options[:locals][:json] = self
190186
@context.render options
191187
end
192188

0 commit comments

Comments
 (0)