aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/engines/memory/relations/array.rb
blob: 6486dcbcc1b29f022ce56d984d83ccbd9180ad5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module Arel
  class Array
    include Relation

    attributes :array,  :attribute_names_and_types
    include Recursion::BaseCase
    deriving :==, :initialize

    def initialize(array, attribute_names_and_types)
      @array, @attribute_names_and_types = array, attribute_names_and_types
    end

    def engine
      @engine ||= Memory::Engine.new
    end

    def attributes
      @attributes ||= @attribute_names_and_types.collect do |attribute, type|
        attribute = type.new(self, attribute) if Symbol === attribute
        attribute
      end
    end

    def format(attribute, value)
      value
    end

    def eval
      @array.collect { |r| Row.new(self, r) }
    end
  end
end