@@ -64,7 +64,7 @@ def set!(key, value = BLANK, *args, &block)
64
64
else
65
65
# json.author @post.creator, :name, :email_address
66
66
# { "author": { "name": "David", "email_address": "[email protected] " } }
67
- _merge_block ( key ) { extract! value , * args }
67
+ _merge_block ( key ) { _extract value , args }
68
68
end
69
69
70
70
_set_value key , result
@@ -221,7 +221,7 @@ def array!(collection = [], *attributes, &block)
221
221
elsif ::Kernel . block_given?
222
222
_map_collection ( collection , &block )
223
223
elsif attributes . any?
224
- _map_collection ( collection ) { |element | extract! element , * attributes }
224
+ _map_collection ( collection ) { |element | _extract element , attributes }
225
225
else
226
226
_format_keys ( collection . to_a )
227
227
end
@@ -247,18 +247,14 @@ def array!(collection = [], *attributes, &block)
247
247
#
248
248
# json.(@person, :name, :age)
249
249
def extract! ( object , *attributes )
250
- if ::Hash === object
251
- _extract_hash_values ( object , attributes )
252
- else
253
- _extract_method_values ( object , attributes )
254
- end
250
+ _extract object , attributes
255
251
end
256
252
257
253
def call ( object , *attributes , &block )
258
254
if ::Kernel . block_given?
259
255
array! object , &block
260
256
else
261
- extract! object , * attributes
257
+ _extract object , attributes
262
258
end
263
259
end
264
260
@@ -287,6 +283,14 @@ def target!
287
283
288
284
private
289
285
286
+ def _extract ( object , attributes )
287
+ if ::Hash === object
288
+ _extract_hash_values ( object , attributes )
289
+ else
290
+ _extract_method_values ( object , attributes )
291
+ end
292
+ end
293
+
290
294
def _extract_hash_values ( object , attributes )
291
295
attributes . each { |key | _set_value key , _format_keys ( object . fetch ( key ) ) }
292
296
end
0 commit comments