Module: Zena::Use::DynAttributes::ModelMethods
- Defined in:
- lib/zena/use/dyn_attributes.rb
Overview
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/zena/use/dyn_attributes.rb', line 245
def method_missing(sym,*args)
if sym.to_s =~ /^d_(.*?)(=|)$/
if $2 == '='
self.prop[$1] = args[0]
else
self.prop[$1]
end
else
super
end
end
|
Class Method Details
.included(base) ⇒ Object
this is called when the module is included into the ‘base’ module
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/zena/use/dyn_attributes.rb', line 202
def self.included(base)
base.extend Zena::Use::DynAttributes::ClassMethods
base.has_many :dynamic_attributes, :foreign_key => 'owner_id', :table_name => 'dyn_attributes', :class_name => 'DynAttribute'
base.after_save :save_dynamic_attributes
base.after_destroy :destroy_attributes
base.class_eval <<-END
def self.dyn_attribute_options
{:table_name => 'dyn_attributes'}
end
END
end
|
Instance Method Details
#dyn ⇒ Object
219
220
221
|
# File 'lib/zena/use/dyn_attributes.rb', line 219
def dyn
@dyn_attributes ||= DynAttributeProxy.for(self, self.class.dyn_attribute_options)
end
|
#dyn=(dyn_attributes) ⇒ Object
223
224
225
226
227
228
229
|
# File 'lib/zena/use/dyn_attributes.rb', line 223
def dyn=(dyn_attributes)
if dyn_attributes.kind_of?(DynAttributeProxy)
@dyn_attributes = dyn_attributes.clone_for(self, self.class.dyn_attribute_options)
else
dyn.update_with(dyn_attributes)
end
end
|
#dyn_attributes=(attributes) ⇒ Object
231
232
233
|
# File 'lib/zena/use/dyn_attributes.rb', line 231
def dyn_attributes=(attributes)
dyn.attributes = attributes
end
|