Module: CouchRest::Model::DesignDoc::ClassMethods
- Defined in:
- lib/couchrest/model/design_doc.rb
Instance Method Summary collapse
- #design_doc ⇒ Object
- #design_doc_id ⇒ Object
- #design_doc_slug ⇒ Object
- #design_doc_uri(db = database) ⇒ Object
-
#save_design_doc(db = database, force = false) ⇒ Object
Save the design doc onto a target database in a thread-safe way, not modifying the model’s design_doc.
-
#save_design_doc!(db = database) ⇒ Object
Force the update of the model’s design_doc even if it hasn’t changed.
-
#stored_design_doc(db = database) ⇒ Object
Retreive the latest version of the design document directly from the database.
Instance Method Details
#design_doc ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/couchrest/model/design_doc.rb', line 9 def design_doc @design_doc ||= if auto_update_design_doc ::CouchRest::Design.new(default_design_doc) else stored_design_doc || ::CouchRest::Design.new(default_design_doc) end end |
#design_doc_id ⇒ Object
17 18 19 |
# File 'lib/couchrest/model/design_doc.rb', line 17 def design_doc_id "_design/#{design_doc_slug}" end |
#design_doc_slug ⇒ Object
21 22 23 |
# File 'lib/couchrest/model/design_doc.rb', line 21 def design_doc_slug self.to_s end |
#design_doc_uri(db = database) ⇒ Object
25 26 27 |
# File 'lib/couchrest/model/design_doc.rb', line 25 def design_doc_uri(db = database) "#{db.root}/#{design_doc_id}" end |
#save_design_doc(db = database, force = false) ⇒ Object
Save the design doc onto a target database in a thread-safe way, not modifying the model’s design_doc
See also save_design_doc! to always save the design doc even if there are no changes.
46 47 48 |
# File 'lib/couchrest/model/design_doc.rb', line 46 def save_design_doc(db = database, force = false) update_design_doc(db, force) end |
#save_design_doc!(db = database) ⇒ Object
Force the update of the model’s design_doc even if it hasn’t changed.
51 52 53 |
# File 'lib/couchrest/model/design_doc.rb', line 51 def save_design_doc!(db = database) save_design_doc(db, true) end |
#stored_design_doc(db = database) ⇒ Object
Retreive the latest version of the design document directly from the database. This is never cached and will return nil if the design is not present.
Use this method if you’d like to compare revisions [_rev] which is not stored in the normal design doc.
35 36 37 38 39 |
# File 'lib/couchrest/model/design_doc.rb', line 35 def stored_design_doc(db = database) db.get(design_doc_id) rescue RestClient::ResourceNotFound nil end |