Module: SimplyCouch::Model::Persistence::Json::ClassMethods

Defined in:
lib/simply_couch/model/persistence.rb

Instance Method Summary collapse

Instance Method Details

#json_create(json) ⇒ Object

Called by JSON.parse to hydrate documents into model instances. Looks for ‘ruby_class’ key (mozo convention) or ‘json_class’ (standard).



272
273
274
275
276
277
278
279
280
281
# File 'lib/simply_couch/model/persistence.rb', line 272

def json_create(json)
  return if json.nil?
  doc = ActiveSupport::HashWithIndifferentAccess.new(json)
  instance = new
  instance.instance_variable_set(:@_document, doc)
  instance._id = doc[:_id] || doc['_id']
  instance._rev = doc[:_rev] || doc['_rev']
  instance._attachments = doc[:_attachments] || doc['_attachments']
  instance
end