3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/json_representations/collection.rb', line 3
def self.included(base)
base.class_eval do
def representation(name=nil, options={})
subject = self
if respond_to?(:klass) && klass.respond_to?(:representations)
QUERY_METHODS.each do |method|
next unless respond_to? method
args = klass.representations.dig(name, method)
subject = subject.public_send(method, args) if args
end
end
return super if respond_to? :super
subject.map do |item|
item.respond_to?(:representation) ? item.representation(name, options) : item
end
end
end
end
|