Sha256: 3365bc0e706121bf34bfb808494c35ae3456f3804492b09ca7e17e5abc3622be

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

module Datagrid
  module Drivers
    # @!visibility private
    class Array < AbstractDriver

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

      def to_scope(scope)
        scope
      end

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

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

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

      def default_order(scope, column_name)
        column_name
      end

      def reverse_order(scope)
        scope.reverse
      end

      def greater_equal(scope, field, value)
        scope.select do |object|
          object.public_send(field) >= value
        end
      end

      def less_equal(scope, field, value)
        scope.select do |object|
          object.public_send(field) <= 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.public_send(column_name).class)
      end

      def contains(scope, field, value)
        scope.select do |object|
          object.public_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

      def can_preload?(scope, association)
        false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datagrid-1.8.2 lib/datagrid/drivers/array.rb