Sha256: e0fba8d0bfaa497efd66c0afc2f7d7c5568af1cbad85fb6e2de19eff29e64096

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 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.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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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