Module: CouchRest::Model::InstanceMethods
- Defined in:
- lib/couchrest/core/model.rb
Overview
instance methods on the model classes
Instance Attribute Summary collapse
-
#doc ⇒ Object
Returns the value of attribute doc.
Instance Method Summary collapse
-
#database ⇒ Object
returns the database used by this model’s class.
-
#id ⇒ Object
alias for doc.
- #initialize(keys = {}) ⇒ Object
-
#new_record? ⇒ Boolean
returns true if the doc has never been saved.
-
#rev ⇒ Object
alias for doc.
-
#save ⇒ Object
save the doc to the db using create or update.
Instance Attribute Details
#doc ⇒ Object
Returns the value of attribute doc.
52 53 54 |
# File 'lib/couchrest/core/model.rb', line 52 def doc @doc end |
Instance Method Details
#database ⇒ Object
returns the database used by this model’s class
65 66 67 |
# File 'lib/couchrest/core/model.rb', line 65 def database self.class.database end |
#id ⇒ Object
alias for doc
70 71 72 |
# File 'lib/couchrest/core/model.rb', line 70 def id doc['_id'] end |
#initialize(keys = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/couchrest/core/model.rb', line 54 def initialize keys = {} self.doc = {} keys.each do |k,v| doc[k.to_s] = v end unless doc['_id'] && doc['_rev'] init_doc end end |
#new_record? ⇒ Boolean
returns true if the doc has never been saved
80 81 82 |
# File 'lib/couchrest/core/model.rb', line 80 def new_record? !doc['_rev'] end |
#rev ⇒ Object
alias for doc
75 76 77 |
# File 'lib/couchrest/core/model.rb', line 75 def rev doc['_rev'] end |
#save ⇒ Object
save the doc to the db using create or update
85 86 87 88 89 90 91 |
# File 'lib/couchrest/core/model.rb', line 85 def save if new_record? create else update end end |