Sha256: 0ec4b99034666bf72ceb7576d3fb9749f71ce5e89c350fff50b133f7788f3ff8

Contents?: true

Size: 1.77 KB

Versions: 13

Compression:

Stored size: 1.77 KB

Contents

module Datagrid
  module Drivers
    class Array < AbstractDriver #:nodoc:

      def self.match?(scope)
        !Datagrid::Drivers::ActiveRecord.match?(scope) && (scope.is_a?(::Array) || scope.is_a?(Enumerator))
      end

      def to_scope(scope)
        scope
      end

      def where(scope, attribute, value)
        scope.select do |object|
          object.send(attribute) == value
        end
      end

      def asc(scope, order)
        return scope unless order
        return scope if order.empty?
        scope.sort_by do |object|
          object.send(order)
        end
      end

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

      def default_order(scope, column_name)
        column_name
      end

      def greater_equal(scope, field, value)
        scope.select do |object|
          compare_value = object.send(field)
          compare_value.respond_to?(:>=) && compare_value >= value
        end
      end

      def less_equal(scope, field, value)
        scope.select do |object|
          compare_value = object.send(field)
          compare_value.respond_to?(:<=) && compare_value <= value
        end
      end

      def has_column?(scope, column_name)
        scope.any? && scope.first.respond_to?(column_name)
      end

      def is_timestamp?(scope, column_name)
        has_column?(scope, column_name) &&
          timestamp_class?(scope.first.send(column_name).class)
      end

      def contains(scope, field, value)
        scope.select do |object|
          object.send(field).to_s.include?(value)
        end
      end

      def column_names(scope)
        []
      end

      def batch_each(scope, batch_size, &block)
        scope.each(&block)
      end
      
      def default_cache_key(asset)
        asset
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
datagrid-1.4.4 lib/datagrid/drivers/array.rb
datagrid-1.4.3 lib/datagrid/drivers/array.rb
datagrid-1.4.2 lib/datagrid/drivers/array.rb
datagrid-1.4.1 lib/datagrid/drivers/array.rb
datagrid-1.4.0 lib/datagrid/drivers/array.rb
datagrid-1.3.9 lib/datagrid/drivers/array.rb
datagrid-1.3.7 lib/datagrid/drivers/array.rb
datagrid-1.3.6 lib/datagrid/drivers/array.rb
datagrid-1.3.5 lib/datagrid/drivers/array.rb
datagrid-1.3.4 lib/datagrid/drivers/array.rb
datagrid-1.3.3 lib/datagrid/drivers/array.rb
datagrid-1.3.2 lib/datagrid/drivers/array.rb
datagrid-1.3.1 lib/datagrid/drivers/array.rb