aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/algebra/relations/row.rb
blob: 84f19e372f5b9ac267dfdfef96d38e6844d825bc (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
module Arel
  class Row
    attr_reader :tuple, :relation

    def initialize relation, tuple
      @relation = relation
      @tuple = tuple
    end

    def [](attribute)
      attribute.type_cast(tuple[relation.position_of(attribute)])
    end

    def slice(*attributes)
      Row.new(relation, attributes.map do |attribute|
        # FIXME TESTME method chaining
        tuple[relation.relation.position_of(attribute)]
      end)
    end

    def bind(relation)
      Row.new(relation, tuple)
    end

    def combine(other, relation)
      Row.new(relation, tuple + other.tuple)
    end
  end
end