3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/freeskimer/model_additions.rb', line 3
def freeskim(att, options)
raise "'to' attribitute is missing" unless options[:to]
send :define_method, att do
tmp = JSON.parse(send(options[:to]).to_s) if send(options[:to])
tmp[att.to_s] if tmp and tmp[att.to_s]
end
send :define_method, "#{att}=" do |value|
value = yield(value) if block_given?
tmp = {}
tmp = JSON.parse send options[:to] if send options[:to]
tmp[att] = value
send("#{options[:to]}=", tmp.to_json)
end
end
|