Module: Ooor::FieldMethods
- Extended by:
- ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/ooor/field_methods.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
# Raise NoMethodError if the named attribute does not exist in order to preserve behavior expected by #clone.
def attribute(name)
key = name.to_s
if self.class.fields.has_key?(key) get_attribute(key)
elsif self.class.associations_keys.index(key)
get_association(key)
else
raise NoMethodError
end
end
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/ooor/field_methods.rb', line 197
def method_missing(method_symbol, *arguments)
self.class.reload_fields_definition(false)
if id
rpc_execute(method_symbol, [id], *arguments) else
super
end
rescue UnknownAttributeOrAssociationError => e
e.klass = self.class
raise e
end
|
Instance Attribute Details
#_display_name ⇒ Object
Also known as:
_name
Returns the value of attribute _display_name.
109
110
111
|
# File 'lib/ooor/field_methods.rb', line 109
def _display_name
@_display_name
end
|
Instance Method Details
#_destroy ⇒ Object
116
117
118
|
# File 'lib/ooor/field_methods.rb', line 116
def _destroy
@marked_for_destruction
end
|
#_destroy=(dummy) ⇒ Object
112
113
114
|
# File 'lib/ooor/field_methods.rb', line 112
def _destroy=(dummy)
@marked_for_destruction = true unless dummy.blank? || ["false", "0", 0].index(dummy)
end
|
#get_association(meth, *args) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/ooor/field_methods.rb', line 147
def get_association(meth, *args)
return @associations[meth] || :undef if @skip
lazy_load(meth, *args) if @lazy
if @loaded_associations.has_key?(meth)
@loaded_associations[meth]
elsif @associations.has_key?(meth)
@loaded_associations[meth] = relationnal_result(meth, *args)
else
if @attributes["id"]
@associations[meth] = rpc_execute('read', [@attributes["id"]], [meth], *args || context)[0][meth]
@loaded_associations[meth] = relationnal_result(meth, *args)
elsif self.class.one2many_associations.has_key?(meth) || self.class.many2many_associations.has_key?(meth)
load_x2m_association(meth, [], *args)
else
nil
end
end
end
|
#get_attribute(meth, *args) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/ooor/field_methods.rb', line 127
def get_attribute(meth, *args)
lazy_load(meth, *args) if @lazy
if @attributes.has_key?(meth)
@attributes[meth]
else if @attributes["id"]
@attributes[meth] = rpc_execute('read', [@attributes["id"]], [meth], *args || context)[0][meth]
else
nil
end
end
end
|
#lazy_load(meth, *args) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/ooor/field_methods.rb', line 120
def lazy_load(meth, *args)
@lazy = false
load(rpc_execute('read', [id], (self.class.fast_fields + [meth]).uniq, *args || context)[0]).tap do
@lazy = false
end
end
|
#set_association(meth, *args) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/ooor/field_methods.rb', line 166
def set_association(meth, *args)
value = sanitize_association(meth, args[0])
if self.class.many2one_associations.has_key?(meth) if @associations[meth].is_a?(Array) && @associations[meth][0] == value \
|| @associations[meth] == value return value
end
end
@skip = true
send("#{meth}_will_change!")
@skip = false
if value.is_a?(Ooor::Base) || value.is_a?(Array) && !value.empty? && value.all? {|i| i.is_a?(Ooor::Base)}
@loaded_associations[meth] = value
else
@loaded_associations.delete(meth)
end
@associations[meth] = value
end
|
#set_attribute(meth, *args) ⇒ Object
140
141
142
143
144
145
|
# File 'lib/ooor/field_methods.rb', line 140
def set_attribute(meth, *args)
value = sanitize_attribute(meth, args[0])
@attributes[meth] ||= nil
send("#{meth}_will_change!") unless @attributes[meth] == value
@attributes[meth] = value
end
|