Class: Arel::Header
- Inherits:
-
Object
- Object
- Arel::Header
- Includes:
- Enumerable
- Defined in:
- lib/arel/algebra/header.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #bind(relation) ⇒ Object
- #each(&block) ⇒ Object
-
#index(i) ⇒ Object
TMP.
-
#initialize(attrs = []) ⇒ Header
constructor
A new instance of Header.
- #to_ary ⇒ Object
- #union(other) ⇒ Object (also: #|)
Constructor Details
#initialize(attrs = []) ⇒ Header
Returns a new instance of Header.
5 6 7 8 9 10 |
# File 'lib/arel/algebra/header.rb', line 5 def initialize(attrs = []) @attributes = attrs.to_ary @names = Hash.new do |h,k| h[k] = @attributes.detect { |a| a.named?(k) } end end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 |
# File 'lib/arel/algebra/header.rb', line 24 def ==(other) to_set == other.to_set end |
#[](key) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/arel/algebra/header.rb', line 17 def [](key) case key when String, Symbol then find_by_name(key) when Attribute then find_by_attribute(key) end end |
#bind(relation) ⇒ Object
38 39 40 |
# File 'lib/arel/algebra/header.rb', line 38 def bind(relation) Header.new(map { |a| a.bind(relation) }) end |
#each(&block) ⇒ Object
12 13 14 15 |
# File 'lib/arel/algebra/header.rb', line 12 def each(&block) to_ary.each(&block) self end |
#index(i) ⇒ Object
TMP
43 44 45 |
# File 'lib/arel/algebra/header.rb', line 43 def index(i) to_ary.index(i) end |
#to_ary ⇒ Object
34 35 36 |
# File 'lib/arel/algebra/header.rb', line 34 def to_ary @attributes end |
#union(other) ⇒ Object Also known as: |
28 29 30 |
# File 'lib/arel/algebra/header.rb', line 28 def union(other) new(to_ary | other) end |