7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/couchbase/model/complex_attributes.rb', line 7
def array_attribute(*names)
options = names.
class_name = options.delete(:class_name)
names.each do |name|
name = name.to_s
(@_array_attributes ||= {})[name] = class_name
attribute name, {default: proc { [] }}.merge(options)
define_method("#{name}=") do |values|
actual_values = values.map do |value|
if value.is_a?(String) && value =~ /json_class/
JSON.load value
else
value
end
end
write_attribute name, actual_values
end
end
end
|