lib/couchrest/model/designs.rb in couchrest_model-1.1.0.beta4 vs lib/couchrest/model/designs.rb in couchrest_model-1.1.0.beta5
- old
+ new
@@ -63,9 +63,20 @@
def view(name, opts = {})
View.create(model, name, opts)
create_view_method(name)
end
+ # 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.
+ def filter(name, function)
+ filters = (self.model.design_doc['filters'] ||= {})
+ filters[name.to_s] = function
+ end
+
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