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

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

Overview

Support class that allows for a model’s design definition to be converted into an actual design document.

The methods called in a DesignMapper instance will relay the parameters to the appropriate method in the design document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, prefix = nil) ⇒ DesignMapper

Returns a new instance of DesignMapper.



19
20
21
22
23
24
25
26
# File 'lib/couchrest/model/designs/design_mapper.rb', line 19

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



17
18
19
# File 'lib/couchrest/model/designs/design_mapper.rb', line 17

def design_doc
  @design_doc
end

#methodObject

Basic mapper attributes



14
15
16
# File 'lib/couchrest/model/designs/design_mapper.rb', line 14

def method
  @method
end

#modelObject

Basic mapper attributes



14
15
16
# File 'lib/couchrest/model/designs/design_mapper.rb', line 14

def model
  @model
end

#prefixObject

Basic mapper attributes



14
15
16
# File 'lib/couchrest/model/designs/design_mapper.rb', line 14

def prefix
  @prefix
end

Instance Method Details

#disable_auto_updateObject



28
29
30
# File 'lib/couchrest/model/designs/design_mapper.rb', line 28

def disable_auto_update
  design_doc.auto_update = false
end

#enable_auto_updateObject



32
33
34
# File 'lib/couchrest/model/designs/design_mapper.rb', line 32

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.



48
49
50
# File 'lib/couchrest/model/designs/design_mapper.rb', line 48

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

#model_type_keyObject

Convenience wrapper to access model’s type key option.



58
59
60
# File 'lib/couchrest/model/designs/design_mapper.rb', line 58

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.



38
39
40
# File 'lib/couchrest/model/designs/design_mapper.rb', line 38

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

#view_lib(name, function) ⇒ Object

Define a new view re-usable lib for shared functions.



53
54
55
# File 'lib/couchrest/model/designs/design_mapper.rb', line 53

def view_lib(name, function)
  design_doc.create_view_lib(name, function)
end