aboutsummaryrefslogblamecommitdiffstats
path: root/lib/arel/algebra/relations/row.rb
blob: f5fe364b83239a03e7893cb7a7a126a3032e4601 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

           












                                     
 
                     
                                                                 
       
 

                                                                    

                                                                 


              
 


                              
 


                                            
     
   
module Arel
  class Row
    attr_reader :tuple, :relation

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

    def == other
      super ||
        Row === other &&
        relation == other.relation &&
        tuple == other.tuple
    end

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

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

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

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