Module: Representable::Decorator::Coercion

Defined in:
lib/representable/decorator/coercion.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/representable/decorator/coercion.rb', line 5

def self.included(base)
  base.class_eval do
    # DISCUSS: this assumes we have a Representer included, yet.
    alias_method :representable_initialize, :initialize
    alias_method :representable_to_hash,    :to_hash

    # FIXME: allow including coercion only from virtus.
    include Virtus
    undef_method(:initialize)
    undef_method(:to_hash)

    extend Representable::Coercion::ClassMethods
    extend ClassMethods

    def initialize(*args) # override Virtus' #initialize.
      representable_initialize(*args)
    end

    def to_hash(*args) # override Virtus' #to_hash.
      representable_to_hash(*args)
    end
  end
end