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
7
8
9
# File 'lib/couch_potato/persistence/json.rb', line 4

def self.included(base) #:nodoc:
  base.class_eval do
    extend ClassMethods
    attr_accessor :_document
  end
end

Instance Method Details

#to_hashObject

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



17
18
19
20
21
22
# File 'lib/couch_potato/persistence/json.rb', line 17

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



12
13
14
# File 'lib/couch_potato/persistence/json.rb', line 12

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