Module: Supa::Representable::InstanceMethods

Defined in:
lib/supa/representable.rb

Instance Method Summary collapse

Instance Method Details

#initialize(object) ⇒ Object



9
10
11
# File 'lib/supa/representable.rb', line 9

def initialize(object)
  @object = object
end

#to_hashObject



13
14
15
16
17
# File 'lib/supa/representable.rb', line 13

def to_hash
  Supa::Builder.new(representer: self, context: object, tree: {}).tap do |builder|
    builder.instance_exec(&self.class.definition)
  end.to_hash
end

#to_jsonObject



19
20
21
# File 'lib/supa/representable.rb', line 19

def to_json
  to_hash.to_json
end