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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#design_docObject

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_freshObject

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_cacheObject

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_docObject



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_idObject



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

def design_doc_id
  "_design/#{design_doc_slug}"
end

#design_doc_slugObject



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_docObject



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_docObject

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

#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



65
66
67
# File 'lib/couchrest/mixins/design_doc.rb', line 65

def save_design_doc_on(db)
  update_design_doc(Design.new(design_doc), db)
end