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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ DesignMapper

Returns a new instance of DesignMapper.



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

def initialize(model)
  self.model = model
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



55
56
57
# File 'lib/couchrest/model/designs.rb', line 55

def model
  @model
end

Instance Method Details

#create_view_method(name) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/couchrest/model/designs.rb', line 80

def create_view_method(name)
  model.class_eval <<-EOS, __FILE__, __LINE__ + 1
    def self.#{name}(opts = {})
      CouchRest::Model::Designs::View.new(self, opts, '#{name}')
    end
  EOS
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.



75
76
77
78
# File 'lib/couchrest/model/designs.rb', line 75

def filter(name, function)
  filters = (self.model.design_doc['filters'] ||= {})
  filters[name.to_s] = function
end

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

Generate a method that will provide a new View instance when requested. This will also define the view in CouchDB unless auto_update_design_doc is disabled.



64
65
66
67
# File 'lib/couchrest/model/designs.rb', line 64

def view(name, opts = {})
  View.create(model, name, opts) if model.auto_update_design_doc
  create_view_method(name)
end