Class: ShadyDB::Document

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Includes:
ActiveModel::Validations, Attributes, Finders, Persistence
Defined in:
lib/shadydb/document.rb

Instance Method Summary collapse

Methods included from Persistence

#destroy, #destroyed?, included, #new_record?, #path, #persisted?, #save, #update_attributes

Methods included from Finders

included

Methods included from Attributes

#[], #[]=, #id, included, #method_missing

Constructor Details

#initialize(attribs = {}) ⇒ Document

Returns a new instance of Document.



12
13
14
15
16
17
18
# File 'lib/shadydb/document.rb', line 12

def initialize(attribs = {})
  @new_record = true
  @destroyed = false
  
  self.attributes = attribs.stringify_keys
  self.attributes.reverse_merge!(self.class.fields)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ShadyDB::Attributes

Instance Method Details

#to_keyObject



28
29
30
# File 'lib/shadydb/document.rb', line 28

def to_key
  persisted? ? [id] : nil
end

#to_modelObject



20
21
22
# File 'lib/shadydb/document.rb', line 20

def to_model
  self
end

#to_paramObject



24
25
26
# File 'lib/shadydb/document.rb', line 24

def to_param
  id
end