Class: CouchRest::Model::Designs::DesignMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/couchrest/model/designs.rb

Overview

Map method calls defined in a design block to actions in the Design Document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, prefix = nil) ⇒ DesignMapper



83
84
85
86
87
88
89
90
# File 'lib/couchrest/model/designs.rb', line 83

def initialize(model, prefix = nil)
  self.model  = model
  self.prefix = prefix
  self.method = Design.method_name(prefix)

  create_model_design_doc_reader
  self.design_doc = model.send(method) || assign_model_design_doc
end

Instance Attribute Details

#design_docObject

Temporary variable storing the design doc



81
82
83
# File 'lib/couchrest/model/designs.rb', line 81

def design_doc
  @design_doc
end

#methodObject

Basic mapper attributes



78
79
80
# File 'lib/couchrest/model/designs.rb', line 78

def method
  @method
end

#modelObject

Basic mapper attributes



78
79
80
# File 'lib/couchrest/model/designs.rb', line 78

def model
  @model
end

#prefixObject

Basic mapper attributes



78
79
80
# File 'lib/couchrest/model/designs.rb', line 78

def prefix
  @prefix
end

Instance Method Details

#disable_auto_updateObject



92
93
94
# File 'lib/couchrest/model/designs.rb', line 92

def disable_auto_update
  design_doc.auto_update = false
end

#enable_auto_updateObject



96
97
98
# File 'lib/couchrest/model/designs.rb', line 96

def enable_auto_update
  design_doc.auto_update = true
end

#filter(name, function) ⇒ Object

Really simple design function that allows a filter to be added. Filters are simple functions used when listening to the _changes feed.

No methods are created here, the design is simply updated. See the CouchDB API for more information on how to use this.



112
113
114
# File 'lib/couchrest/model/designs.rb', line 112

def filter(name, function)
  design_doc.create_filter(name, function)
end

#model_type_keyObject

Convenience wrapper to access model's type key option.



117
118
119
# File 'lib/couchrest/model/designs.rb', line 117

def model_type_key
  model.model_type_key
end

#view(name, opts = {}) ⇒ Object

Add the specified view to the design doc the definition was made in and create quick access methods in the model.



102
103
104
# File 'lib/couchrest/model/designs.rb', line 102

def view(name, opts = {})
  design_doc.create_view(name, opts)
end