Module: CouchPotato::Persistence::Json
- Defined in:
- lib/couch_potato/persistence/json.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#to_hash ⇒ Object
returns all the attributes, the ruby class and the _id and _rev of a model as a Hash.
-
#to_json(*args) ⇒ Object
returns a JSON representation of a model in order to store it in CouchDB.
Class Method Details
.included(base) ⇒ Object
:nodoc:
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/couch_potato/persistence/json.rb', line 6 def self.included(base) #:nodoc: base.class_eval do extend ClassMethods attr_writer :_document def _document @_document ||= {} end end end |
Instance Method Details
#to_hash ⇒ Object
returns all the attributes, the ruby class and the _id and _rev of a model as a Hash
23 24 25 26 27 28 |
# File 'lib/couch_potato/persistence/json.rb', line 23 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
18 19 20 |
# File 'lib/couch_potato/persistence/json.rb', line 18 def to_json(*args) to_hash.to_json(*args) end |