Sha256: 34504aa1d9a67f0646ea7722817d5931d30907de47161ac12a4c45e65d77ea49

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

Contents

module Datagrid
  module Drivers
    class ActiveRecord < AbstractDriver

      def self.match?(scope)
        if scope.is_a?(Class) 
          scope.ancestors.include?(::ActiveRecord::Base)
        else
          scope.is_a?(::ActiveRecord::Relation) 
        end
      end

      def to_scope(scope)
        scope.scoped({})
      end

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

      def asc(scope, order)
        # Rails 3.x.x don't able to override already applied order
        # Using #reorder instead
        scope.reorder(order)
      end

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

      def table_name(scope)
        scope.table_name
      end

      def default_order(scope, column_name)
        scope.column_names.include?(column_name.to_s) ? [scope.table_name, column_name].join(".") : nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
datagrid-0.4.1 lib/datagrid/drivers/active_record.rb
datagrid-0.4.0 lib/datagrid/drivers/active_record.rb