Module: CouchRest::Mixins::DesignDoc::ClassMethods
- Defined in:
- lib/couchrest/mixins/design_doc.rb
Instance Attribute Summary collapse
-
#design_doc ⇒ Object
Returns the value of attribute design_doc.
-
#design_doc_fresh ⇒ Object
Returns the value of attribute design_doc_fresh.
-
#design_doc_slug_cache ⇒ Object
Returns the value of attribute design_doc_slug_cache.
Instance Method Summary collapse
- #default_design_doc ⇒ Object
- #design_doc_id ⇒ Object
- #design_doc_slug ⇒ Object
- #refresh_design_doc ⇒ Object
- #refresh_design_doc_on(db) ⇒ Object
-
#save_design_doc ⇒ Object
Save the design doc onto the default database, and update the design_doc attribute.
-
#save_design_doc_on(db) ⇒ Object
Save the design doc onto a target database in a thread-safe way, not modifying the model’s design_doc.
Instance Attribute Details
#design_doc ⇒ Object
Returns the value of attribute design_doc.
12 13 14 |
# File 'lib/couchrest/mixins/design_doc.rb', line 12 def design_doc @design_doc end |
#design_doc_fresh ⇒ Object
Returns the value of attribute design_doc_fresh.
12 13 14 |
# File 'lib/couchrest/mixins/design_doc.rb', line 12 def design_doc_fresh @design_doc_fresh end |
#design_doc_slug_cache ⇒ Object
Returns the value of attribute design_doc_slug_cache.
12 13 14 |
# File 'lib/couchrest/mixins/design_doc.rb', line 12 def design_doc_slug_cache @design_doc_slug_cache end |
Instance Method Details
#default_design_doc ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/couchrest/mixins/design_doc.rb', line 31 def default_design_doc { "language" => "javascript", "views" => { 'all' => { 'map' => "function(doc) { if (doc['couchrest-type'] == '#{self.to_s}') { emit(doc['_id'],1); } }" } } } end |
#design_doc_id ⇒ Object
18 19 20 |
# File 'lib/couchrest/mixins/design_doc.rb', line 18 def design_doc_id "_design/#{design_doc_slug}" end |
#design_doc_slug ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/couchrest/mixins/design_doc.rb', line 22 def design_doc_slug return design_doc_slug_cache if (design_doc_slug_cache && design_doc_fresh) funcs = [] design_doc['views'].each do |name, view| funcs << "#{name}/#{view['map']}#{view['reduce']}" end self.design_doc_slug_cache = self.to_s end |
#refresh_design_doc ⇒ Object
46 47 48 49 |
# File 'lib/couchrest/mixins/design_doc.rb', line 46 def refresh_design_doc reset_design_doc save_design_doc end |
#refresh_design_doc_on(db) ⇒ Object
51 52 53 54 |
# File 'lib/couchrest/mixins/design_doc.rb', line 51 def refresh_design_doc_on(db) reset_design_doc save_design_doc_on(db) end |
#save_design_doc ⇒ Object
Save the design doc onto the default database, and update the design_doc attribute
58 59 60 61 |
# File 'lib/couchrest/mixins/design_doc.rb', line 58 def save_design_doc reset_design_doc unless design_doc_fresh self.design_doc = update_design_doc(design_doc) end |