Class: Prequel::CompositeTuple

Inherits:
Object
  • Object
show all
Defined in:
lib/prequel/composite_tuple.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(left, right) ⇒ CompositeTuple

Returns a new instance of CompositeTuple.



5
6
7
# File 'lib/prequel/composite_tuple.rb', line 5

def initialize(left, right)
  @left, @right = left, right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



3
4
5
# File 'lib/prequel/composite_tuple.rb', line 3

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



3
4
5
# File 'lib/prequel/composite_tuple.rb', line 3

def right
  @right
end

Instance Method Details

#[](name) ⇒ Object



9
10
11
# File 'lib/prequel/composite_tuple.rb', line 9

def [](name)
  get_record(name) || get_field_value(name)
end

#field_valuesObject



27
28
29
# File 'lib/prequel/composite_tuple.rb', line 27

def field_values
  [left.field_values, right.field_values]
end

#get_field_value(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/prequel/composite_tuple.rb', line 17

def get_field_value(name)
  if name =~ /(.+)__(.+)/
    table_name = $1.to_sym
    field_name = $2.to_sym
    get_record(table_name).try(:get_field_value, field_name)
  else
    left.get_field_value(name) || right.get_field_value(name)
  end
end

#get_record(table_name) ⇒ Object



13
14
15
# File 'lib/prequel/composite_tuple.rb', line 13

def get_record(table_name)
  left.get_record(table_name) || right.get_record(table_name)
end