Module: SimplyCouch::Model::Persistence::Json
- Defined in:
- lib/simply_couch/model/persistence.rb
Overview
── JSON ─────────────────────────────────────────────────────────────
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #_document ⇒ Object
- #to_hash(options = nil) ⇒ Object (also: #as_json)
- #to_json(*args) ⇒ Object
Class Method Details
.included(base) ⇒ Object
265 266 267 |
# File 'lib/simply_couch/model/persistence.rb', line 265 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#_document ⇒ Object
263 |
# File 'lib/simply_couch/model/persistence.rb', line 263 def _document; @_document ||= {}; end |
#to_hash(options = nil) ⇒ Object Also known as: as_json
258 259 260 261 |
# File 'lib/simply_couch/model/persistence.rb', line 258 def to_hash( = nil) doc = { 'ruby_class' => self.class.name, '_id' => _id, '_rev' => _rev }.reject { |_, v| v.nil? }.merge(@_document || {}) (self.class.properties || []).inject(doc) {|d, p| p.serialize(d, self); d } end |
#to_json(*args) ⇒ Object
257 |
# File 'lib/simply_couch/model/persistence.rb', line 257 def to_json(*args); to_hash(*args).to_json(*args); end |