Module: CouchPotato::Persistence::Json::ClassMethods

Defined in:
lib/couch_potato/persistence/json.rb

Instance Method Summary collapse

Instance Method Details

#json_create(json) ⇒ Object

creates a model instance from JSON



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/couch_potato/persistence/json.rb', line 33

def json_create(json)
  return if json.nil?
  instance = self.new
  instance._id = json[:_id] || json['_id']
  instance._rev = json[:_rev] || json['_rev']
  instance.instance_variable_set('@skip_dirty_tracking', true)
  properties.each do |property|
    property.build(instance, json)
  end
  instance.instance_variable_set('@skip_dirty_tracking', false)
  # instance.instance_variable_get("@changed_attributes").clear if instance.instance_variable_get("@changed_attributes")
  instance
end