Module: CouchPotato::Persistence::Json

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



4
5
6
# File 'lib/couch_potato/persistence/json.rb', line 4

def self.included(base) #:nodoc:
  base.extend ClassMethods
end

Instance Method Details

#to_hashObject

returns all the attributes, the ruby class and the _id and _rev of a model as a Hash



14
15
16
17
18
19
# File 'lib/couch_potato/persistence/json.rb', line 14

def to_hash
  (self.class.properties).inject({}) do |props, property|
    property.serialize(props, self)
    props
  end.merge(JSON.create_id => self.class.name).merge(id_and_rev_json)
end

#to_json(*args) ⇒ Object

returns a JSON representation of a model in order to store it in CouchDB



9
10
11
# File 'lib/couch_potato/persistence/json.rb', line 9

def to_json(*args)
  to_hash.to_json(*args)
end