Class: LogicalQueryParser::AssocNode

Inherits:
Object
  • Object
show all
Defined in:
lib/logical_query_parser/assoc_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AssocNode

Returns a new instance of AssocNode.



7
8
9
10
11
12
13
# File 'lib/logical_query_parser/assoc_node.rb', line 7

def initialize(options = {})
  options.each do |key, value|
    send("#{key}=", value)
  end
  @columns ||= []
  @children ||= []
end

Instance Attribute Details

#assoc_nameObject

Returns the value of attribute assoc_name.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def assoc_name
  @assoc_name
end

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def children
  @children
end

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def columns
  @columns
end

#klassObject

Returns the value of attribute klass.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def klass
  @klass
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def parent
  @parent
end

#table_nameObject

Returns the value of attribute table_name.



5
6
7
# File 'lib/logical_query_parser/assoc_node.rb', line 5

def table_name
  @table_name
end

Instance Method Details

#arel_tableObject



26
27
28
# File 'lib/logical_query_parser/assoc_node.rb', line 26

def arel_table
  Arel::Table.new(table_name, as: table_name)
end

#descendantsObject



20
21
22
23
24
# File 'lib/logical_query_parser/assoc_node.rb', line 20

def descendants
  children.flat_map do |child|
    [child] + child.descendants
  end
end

#join_structureObject



30
31
32
33
34
35
36
37
38
# File 'lib/logical_query_parser/assoc_node.rb', line 30

def join_structure
  if children.empty?
    {}
  else
    children.each_with_object({}) do |child, hash|
      hash[child.assoc_name] = child.join_structure
    end
  end
end

#model=(model) ⇒ Object



15
16
17
18
# File 'lib/logical_query_parser/assoc_node.rb', line 15

def model=(model)
  @klass = model
  @table_name = model.table_name
end