3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/representable/expandable.rb', line 3
def self.included(base)
base.class_eval do
def self.collection(name, options = {}, &block)
add_expandable(name, options)
super
end
def self.property(name, options = {}, &block)
add_expandable(name, options)
super
end
def self.add_expandable(name, options = {})
if options.delete :expandable
existing_if = options[:if] || ->(_opts) { true }
options[:if] = ->(opts) { opts[:expand] && opts[:expand].include?(name.to_s) && existing_if.call(opts) }
end
end
end
end
|