Module: CouchRest::Mixins::DesignDoc::ClassMethods

Defined in:
lib/couchrest/mixins/design_doc.rb

Instance Method Summary collapse

Instance Method Details

#all_design_doc_versions(db = database) ⇒ Object

DEPRECATED use stored_design_doc to retrieve the current design doc



49
50
51
52
# File 'lib/couchrest/mixins/design_doc.rb', line 49

def all_design_doc_versions(db = database)
  db.documents :startkey => "_design/#{self.to_s}", 
    :endkey => "_design/#{self.to_s}-\u9999"
end

#default_design_docObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/couchrest/mixins/design_doc.rb', line 31

def default_design_doc
  {
    "_id" => design_doc_id,
    "language" => "javascript",
    "views" => {
      'all' => {
        'map' => "function(doc) {
          if (doc['couchrest-type'] == '#{self.to_s}') {
            emit(doc['_id'],1);
          }
        }"
      }
    }
  }
end

#design_docObject



13
14
15
# File 'lib/couchrest/mixins/design_doc.rb', line 13

def design_doc
  @design_doc ||= Design.new(default_design_doc)
end

#design_doc_idObject



23
24
25
# File 'lib/couchrest/mixins/design_doc.rb', line 23

def design_doc_id
  "_design/#{design_doc_slug}"
end

#design_doc_slugObject



27
28
29
# File 'lib/couchrest/mixins/design_doc.rb', line 27

def design_doc_slug
  self.to_s
end

#refresh_design_doc(db = database) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/couchrest/mixins/design_doc.rb', line 61

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_refreshObject

Use when something has been changed, like a view, so that on the next request the design docs will be updated (if changed!)



19
20
21
# File 'lib/couchrest/mixins/design_doc.rb', line 19

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.



74
75
76
# File 'lib/couchrest/mixins/design_doc.rb', line 74

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.



79
80
81
# File 'lib/couchrest/mixins/design_doc.rb', line 79

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.



56
57
58
# File 'lib/couchrest/mixins/design_doc.rb', line 56

def stored_design_doc(db = database)
  db.get(design_doc_id) rescue nil
end