Sha256: 6ce5eaaa63ada9da44724740593da00f70d5efe1b87564b783ee83db68d5fcbc

Contents?: true

Size: 668 Bytes

Versions: 10

Compression:

Stored size: 668 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Scopes
      extend ActiveSupport::Concern

      included do
        class_attribute :_scopes
      end

      module ClassMethods
        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

        def scopes
          self._scopes || self._scopes = {}
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 3 rubygems

Version Path
mongo_mapper-0.12.0 lib/mongo_mapper/plugins/scopes.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/scopes.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.11.0 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.10.1 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.10.0 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.9.2 lib/mongo_mapper/plugins/scopes.rb
mongo_mapper-0.9.1 lib/mongo_mapper/plugins/scopes.rb