50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/proxima/attributes.rb', line 50
def attribute(attribute, klass = nil, json_path = nil, params = nil)
params ||= json_path if json_path.is_a? Hash
params ||= klass if klass.is_a? Hash
params ||= {}
params[:klass] ||= klass if klass.is_a? Class
params[:json_path] ||= json_path if json_path.is_a? String
params[:json_path] ||= klass if klass.is_a? String
params[:json_path] ||= attribute.to_s
attr_reader attribute
define_method("#{attribute}=") do |value|
self.persisted = false
attribute_will_change! attribute
self.instance_variable_set "@#{attribute}", value
Proxima.watch value do
attribute_will_change! attribute
end
end
define_method "#{attribute}?" do
self.instance_variable_get("@#{attribute}") != nil
end
self.define_attribute_method attribute
self.attributes[attribute] = params
end
|