Class: LogicalQueryParser::AssocNode
- Inherits:
-
Object
- Object
- LogicalQueryParser::AssocNode
- Defined in:
- lib/logical_query_parser/assoc_node.rb
Instance Attribute Summary collapse
-
#assoc_name ⇒ Object
Returns the value of attribute assoc_name.
-
#children ⇒ Object
Returns the value of attribute children.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Instance Method Summary collapse
- #arel_table ⇒ Object
- #descendants ⇒ Object
-
#initialize(options = {}) ⇒ AssocNode
constructor
A new instance of AssocNode.
- #join_structure ⇒ Object
- #model=(model) ⇒ Object
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( = {}) .each do |key, value| send("#{key}=", value) end @columns ||= [] @children ||= [] end |
Instance Attribute Details
#assoc_name ⇒ Object
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 |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/logical_query_parser/assoc_node.rb', line 5 def children @children end |
#columns ⇒ Object
Returns the value of attribute columns.
5 6 7 |
# File 'lib/logical_query_parser/assoc_node.rb', line 5 def columns @columns end |
#klass ⇒ Object
Returns the value of attribute klass.
5 6 7 |
# File 'lib/logical_query_parser/assoc_node.rb', line 5 def klass @klass end |
#parent ⇒ Object
Returns the value of attribute parent.
5 6 7 |
# File 'lib/logical_query_parser/assoc_node.rb', line 5 def parent @parent end |
#table_name ⇒ Object
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_table ⇒ Object
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 |
#descendants ⇒ Object
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_structure ⇒ Object
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 |