Class: Arel::Header

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arel/algebra/header.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs = []) ⇒ Header

Returns a new instance of Header.



5
6
7
8
# File 'lib/arel/algebra/header.rb', line 5

def initialize(attrs = [])
  @attributes = attrs.to_ary
  @names      = {}
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/arel/algebra/header.rb', line 22

def ==(other)
  to_set == other.to_set
end

#[](key) ⇒ Object



15
16
17
18
19
20
# File 'lib/arel/algebra/header.rb', line 15

def [](key)
  case key
  when String, Symbol then find_by_name(key)
  when Attribute      then find_by_attribute(key)
  end
end

#bind(relation) ⇒ Object



36
37
38
# File 'lib/arel/algebra/header.rb', line 36

def bind(relation)
  Header.new(map { |a| a.bind(relation) })
end

#eachObject



10
11
12
13
# File 'lib/arel/algebra/header.rb', line 10

def each
  to_ary.each { |e| yield e }
  self
end

#index(i) ⇒ Object

TMP



41
42
43
# File 'lib/arel/algebra/header.rb', line 41

def index(i)
  to_ary.index(i)
end

#to_aryObject



32
33
34
# File 'lib/arel/algebra/header.rb', line 32

def to_ary
  @attributes
end

#union(other) ⇒ Object Also known as: |



26
27
28
# File 'lib/arel/algebra/header.rb', line 26

def union(other)
  new(to_ary | other)
end