Module: MongoMapper::Plugins::Scopes::ClassMethods

Defined in:
lib/mongo_mapper/plugins/scopes.rb

Instance Method Summary collapse

Instance Method Details

#scope(name, scope_options = {}) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/mongo_mapper/plugins/scopes.rb', line 6

def scope(name, scope_options={})
  scopes[name] = lambda do |*args|
    result = scope_options.is_a?(Proc) ? scope_options.call(*args) : scope_options
    result = self.query(result) if result.is_a?(Hash)
    self.query.merge(result)
  end
  singleton_class.send :define_method, name, &scopes[name]
end

#scopesObject



15
16
17
# File 'lib/mongo_mapper/plugins/scopes.rb', line 15

def scopes
  read_inheritable_attribute(:scopes) || write_inheritable_attribute(:scopes, {})
end