Sha256: 63a0d22573cec27cfaa98092306235f0967947a2195501391df5e207cf5c2b5c

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

module Datagrid
  module Drivers
    class MongoMapper < AbstractDriver

      def self.match?(scope)
        return false unless defined?(::MongoMapper)
        if scope.is_a?(Class) 
          scope.ancestors.include?(::MongoMapper::Document)
        else
          scope.is_a?(::Plucky::Query)
        end
      end

      def to_scope(scope)
        scope.where
      end

      def where(scope, attribute, value)
        scope.where(attribute => value)
      end

      def asc(scope, order)
        scope.sort(order.asc)
      end

      def desc(scope, order)
        scope.sort(order.desc)
      end

      def default_order(scope, column_name)
        has_column?(scope, column_name) ? column_name : nil
      end

      def greater_equal(scope, field, value)
        scope.where(field => {"$gte" => value})
      end

      def less_equal(scope, field, value)
        scope.where(field => {"$lte" => value})
      end

      def has_column?(scope, column_name)
        scope.key?(column_name)
      end

      def is_timestamp?(scope, column_name)
        #TODO implement the support
        false
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
datagrid-0.9.3 lib/datagrid/drivers/mongo_mapper.rb
datagrid-0.9.2 lib/datagrid/drivers/mongo_mapper.rb
datagrid-0.9.0 lib/datagrid/drivers/mongo_mapper.rb
datagrid-0.8.4 lib/datagrid/drivers/mongo_mapper.rb