Module: CouchRest::Mixins::DesignDoc::ClassMethods
- Defined in:
- lib/couchrest/mixins/design_doc.rb
Instance Method Summary collapse
-
#all_design_doc_versions(db = database) ⇒ Object
DEPRECATED use stored_design_doc to retrieve the current design doc.
- #default_design_doc ⇒ Object
- #design_doc ⇒ Object
- #design_doc_id ⇒ Object
- #design_doc_slug ⇒ Object
- #refresh_design_doc(db = database) ⇒ Object
-
#req_design_doc_refresh ⇒ Object
Use when something has been changed, like a view, so that on the next request the design docs will be updated (if changed!).
-
#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
(also: #model_design_doc)
Retreive the latest version of the design document directly from the database.
Instance Method Details
#all_design_doc_versions(db = database) ⇒ Object
DEPRECATED use stored_design_doc to retrieve the current design doc
81 82 83 84 |
# File 'lib/couchrest/mixins/design_doc.rb', line 81 def all_design_doc_versions(db = database) db.documents :startkey => "#{design_doc_id}", :endkey => "#{design_doc_id}-\u9999" end |
#default_design_doc ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/couchrest/mixins/design_doc.rb', line 62 def default_design_doc type_field = CouchRest.type_field { "_id" => design_doc_id, "language" => "javascript", "views" => { 'all' => { 'map' => "function(doc) { if (doc['#{type_field}'] == '#{self.to_s}') { emit(doc['_id'],1); } }" } } } end |
#design_doc ⇒ Object
44 45 46 |
# File 'lib/couchrest/mixins/design_doc.rb', line 44 def design_doc @design_doc ||= Design.new(default_design_doc) end |
#design_doc_id ⇒ Object
54 55 56 |
# File 'lib/couchrest/mixins/design_doc.rb', line 54 def design_doc_id "_design/#{design_doc_slug}" end |
#design_doc_slug ⇒ Object
58 59 60 |
# File 'lib/couchrest/mixins/design_doc.rb', line 58 def design_doc_slug CouchRest.design_name_fun.call self end |
#refresh_design_doc(db = database) ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/couchrest/mixins/design_doc.rb', line 93 def refresh_design_doc(db = database) raise "Database missing for design document refresh" if db.nil? unless design_doc_fresh(db) save_design_doc(db) design_doc_fresh(db, true) end end |
#req_design_doc_refresh ⇒ Object
Use when something has been changed, like a view, so that on the next request the design docs will be updated (if changed!)
50 51 52 |
# File 'lib/couchrest/mixins/design_doc.rb', line 50 def req_design_doc_refresh @design_doc_fresh = { } 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.
106 107 108 |
# File 'lib/couchrest/mixins/design_doc.rb', line 106 def save_design_doc(db = database, force = false) update_design_doc(Design.new(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.
111 112 113 |
# File 'lib/couchrest/mixins/design_doc.rb', line 111 def save_design_doc!(db = database) save_design_doc(db, true) end |
#stored_design_doc(db = database) ⇒ Object Also known as: model_design_doc
Retreive the latest version of the design document directly from the database.
88 89 90 |
# File 'lib/couchrest/mixins/design_doc.rb', line 88 def stored_design_doc(db = database) db.get(design_doc_id) rescue nil end |