Class: CouchDB::Document
Instance Attribute Summary collapse
Attributes inherited from JSONObject
#errors
Instance Method Summary
collapse
Methods inherited from JSONObject
#[]=, dynamic_structure!, dynamic_structure?, fixed_structure!, fixed_structure?, #inspect, lookup, #merge, #merge!, properties, property, #replace, #store, #update, #valid?, #validate!
Constructor Details
#initialize(db, attributes = nil) ⇒ Document
Returns a new instance of Document.
15
16
17
18
19
|
# File 'lib/couchdb/document.rb', line 15
def initialize(db, attributes = nil)
super attributes
@db = db
send :after_initialize if respond_to?(:after_initialize)
end
|
Instance Attribute Details
#db ⇒ Object
Returns the value of attribute db.
13
14
15
|
# File 'lib/couchdb/document.rb', line 13
def db
@db
end
|
Instance Method Details
#_id ⇒ Object
Also known as:
id
27
28
29
|
# File 'lib/couchdb/document.rb', line 27
def _id
self['_id']
end
|
#_rev ⇒ Object
Also known as:
rev
21
22
23
|
# File 'lib/couchdb/document.rb', line 21
def _rev
self['_rev']
end
|
#delete! ⇒ Object
48
49
50
51
52
|
# File 'lib/couchdb/document.rb', line 48
def delete!
raise InvalidOperation, "Can not delete a document without _id or _rev." unless id and rev
send :before_delete if respond_to?(:before_delete)
db.delete id, rev
end
|
#new_record? ⇒ Boolean
33
34
35
|
# File 'lib/couchdb/document.rb', line 33
def new_record?
_id.nil?
end
|
#save ⇒ Object
37
38
39
40
|
# File 'lib/couchdb/document.rb', line 37
def save
send :before_save if respond_to?(:before_save)
replace db.put(self)
end
|
#update!(attributes) ⇒ Object
42
43
44
45
46
|
# File 'lib/couchdb/document.rb', line 42
def update!(attributes)
send :before_update if respond_to?(:before_update)
update attributes
save
end
|