Module: Hari::Entity::Serialization::ClassMethods
- Defined in:
- lib/hari/entity/serialization.rb
Instance Method Summary collapse
Instance Method Details
#from_hash(source) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hari/entity/serialization.rb', line 59 def from_hash(source) hash = source.inject({}) do |buffer, (key, value)| if prop = properties.find { |p| p.name == key } buffer[key] = prop.desserialize(value) end buffer end new(hash).tap { |e| e.changed_attributes.clear } end |
#from_json(source) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/hari/entity/serialization.rb', line 71 def from_json(source) return if source.blank? case source when ::String from_hash Yajl::Parser.parse(source) when ::Hash from_hash source end end |