Module: Representable::Coercion

Defined in:
lib/representable/coercion.rb

Defined Under Namespace

Modules: ClassMethods Classes: Coercer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

separate coercion object doesn’t give us initializer and accessors in the represented object (with module representer)!



15
16
17
18
19
20
21
22
# File 'lib/representable/coercion.rb', line 15

def self.included(base)
  base.class_eval do
    extend ClassMethods
    # FIXME: use inheritable_attr when it's ready.
    representable_attrs.inheritable_array(:coercer_class) << Class.new(Coercer) unless representable_attrs.inheritable_array(:coercer_class).first
  end

end

Instance Method Details

#coercerObject



39
40
41
# File 'lib/representable/coercion.rb', line 39

def coercer
  @coercer ||= representable_attrs.inheritable_array(:coercer_class).first.new
end