Sha256: 1b4b919f30d98a1151c7c2bc5017473b8c4514bf276b9f60d3fc42b4904edf88

Contents?: true

Size: 925 Bytes

Versions: 2

Compression:

Stored size: 925 Bytes

Contents

module Datagrid
  module Drivers
    class Mongoid < AbstractDriver

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

      def to_scope(scope)
        scope.where
      end

      def where(scope, condition)
        scope.where(condition)
      end

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

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

      def default_order(scope, column_name)
        scope.fields.keys.include?(column_name.to_s) ? 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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datagrid-0.5.4 lib/datagrid/drivers/mongoid.rb
datagrid-0.5.3 lib/datagrid/drivers/mongoid.rb