Module: Representable::JSON::ClassMethods

Defined in:
lib/representable/json.rb

Instance Method Summary collapse

Instance Method Details

#binding_for_definition(definition) ⇒ Object



23
24
25
# File 'lib/representable/json.rb', line 23

def binding_for_definition(definition)
  (BINDING_FOR_TYPE[definition.sought_type] or ObjectBinding).new(definition)
end

#from_hash(data) ⇒ Object



38
39
40
41
42
# File 'lib/representable/json.rb', line 38

def from_hash(data)
  create_from_json.tap do |object|
    object.update_properties_from(data)
  end
end

#from_json(data, *args, &block) ⇒ Object

Creates a new Ruby object from XML using mapping information declared in the class.

Example:

book = Book.from_xml("<book><name>Beyond Java</name></book>")

DISCUSS: assumes shitty wrapping like :article => => …



32
33
34
35
36
# File 'lib/representable/json.rb', line 32

def from_json(data, *args, &block)
  create_from_json.tap do |object|
    object.from_json(data, *args, &block)
  end
end