Module: Representable::Coercion::ClassMethods
- Defined in:
- lib/representable/coercion.rb
Instance Method Summary collapse
Instance Method Details
#property(name, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/representable/coercion.rb', line 25 def property(name, ={}) return super unless [:type] representable_attrs.inheritable_array(:coercer_class).first.attribute(name, [:type]) # By using :getter we "pre-occupy" this directive, but we avoid creating accessors, which i find is the cleaner way. [:exec_context] = :decorator [:getter] = lambda { |*| coercer.coerce(name, represented.send(name)) } [:setter] = lambda { |v,*| represented.send("#{name}=", coercer.coerce(name, v)) } super end |