Sha256: 9001ed4b66bdafb436887ba804ddc8f74ef99e9fdb4470bb782a859c5ccc4301

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module Datagrid
  module Drivers
    class Array < AbstractDriver

      def self.match?(scope)
        !Datagrid::Drivers::ActiveRecord.match?(scope) && scope.is_a?(::Array)
      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|
          object.send(field) >= value
        end
      end

      def less_equal(scope, field, value)
        scope.select do |object|
          object.send(field) <= value
        end
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datagrid-0.8.3 lib/datagrid/drivers/array.rb
datagrid-0.8.2 lib/datagrid/drivers/array.rb
datagrid-0.8.1 lib/datagrid/drivers/array.rb