Sha256: c1005e4062f5540d716e2d74323cc615c01c969ef4aef659742f3517d2b97ef5

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

module Datagrid
  module Drivers
    class AbstractDriver

      TIMESTAMP_CLASSES = [DateTime, Time, ActiveSupport::TimeWithZone]

      class_attribute :subclasses

      def self.inherited(base)
        super(base)
        self.subclasses ||= []
        self.subclasses << base
      end

      def self.guess_driver(scope)
        self.subclasses.find do |driver_class|
          driver_class.match?(scope)
        end || raise(Datagrid::ConfigurationError, "ORM Driver not found for scope: #{scope.inspect}.")
      end

      def self.match?(scope)
        raise NotImplementedError
      end

      def match?(scope)
        self.class.match?(scope)
      end

      def to_scope(scope)
        raise NotImplementedError
      end

      def where(scope, attribute, value)
        raise NotImplementedError
      end

      def asc(scope, order)
        raise NotImplementedError
      end

      def desc(scope, order)
        raise NotImplementedError
      end

      def default_order(scope, column_name)
        raise NotImplementedError
      end

      def greater_equal(scope, field, value)
        raise NotImplementedError
      end

      def less_equal(scope, field, value)
        raise NotImplementedError
      end
      
      def has_column?(scope, column_name)
        raise NotImplementedError
      end

      def reverse_order(scope)
        raise NotImplementedError
      end

      def is_timestamp?(scope, field)
        raise NotImplementedError
      end

      protected
      def timestamp_class?(klass)
        TIMESTAMP_CLASSES.include?(klass)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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