Module: CouchRest::Model::DesignDoc::ClassMethods
- Defined in:
- lib/couchrest_model_search.rb
Instance Method Summary collapse
- #default_design_doc ⇒ Object
- #orig_default_design_doc ⇒ Object
- #orig_save_design_doc ⇒ Object
- #save_design_doc(db = database, force = false) ⇒ Object
- #update_search_doc ⇒ Object
Instance Method Details
#default_design_doc ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/couchrest_model_search.rb', line 8 def default_design_doc orig_default_design_doc.update "fulltext" => { "by_fulltext" => { "index" => %( function(doc) { var ret = new Document(); function idx(obj) { for (var key in obj){ switch (typeof obj[key]) { case 'object': idx(obj[key]); break; case 'function': break; default: ret.add(obj[key]); break; } } }; if (doc['couchrest-type'] == '#{self.to_s}') { idx(doc); if (doc._attachments) { for (var i in doc._attachments) { ret.attachment('attachment', i); } } } return ret; } ) } } end |
#orig_default_design_doc ⇒ Object
7 |
# File 'lib/couchrest_model_search.rb', line 7 alias_method :orig_default_design_doc, :default_design_doc |
#orig_save_design_doc ⇒ Object
59 |
# File 'lib/couchrest_model_search.rb', line 59 alias_method :orig_save_design_doc, :save_design_doc |
#save_design_doc(db = database, force = false) ⇒ Object
60 61 62 63 |
# File 'lib/couchrest_model_search.rb', line 60 def save_design_doc(db = database, force = false) orig_save_design_doc(db, force) update_search_doc end |
#update_search_doc ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/couchrest_model_search.rb', line 45 def update_search_doc saved = stored_design_doc if saved && saved["fulltext"] != design_doc["fulltext"] saved["fulltext"] = design_doc["fulltext"] saved.save saved elsif !saved design_doc.delete("_rev") design_doc.database = database design_doc.save design_doc end end |