Class: SqlQueryExecutor::Query::SubQuery
- Inherits:
-
Object
- Object
- SqlQueryExecutor::Query::SubQuery
- Defined in:
- lib/sql_query_executor/query/sub_query.rb
Constant Summary collapse
- BINDING_OPERATORS =
{ "or" => "+", "and" => "&" }
- ADD_CHILDREN_METHODS =
{ sentence: :add_sentence_children, sub_query: :add_sub_query_children }
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #execute!(data = []) ⇒ Object
-
#initialize(query, collection) ⇒ SubQuery
constructor
A new instance of SubQuery.
Constructor Details
#initialize(query, collection) ⇒ SubQuery
Returns a new instance of SubQuery.
7 8 9 10 11 12 13 14 |
# File 'lib/sql_query_executor/query/sub_query.rb', line 7 def initialize(query, collection) @collection = collection @query = query @children = [] set_binding_operator set_kind set_children end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
5 6 7 |
# File 'lib/sql_query_executor/query/sub_query.rb', line 5 def children @children end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
5 6 7 |
# File 'lib/sql_query_executor/query/sub_query.rb', line 5 def kind @kind end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/sql_query_executor/query/sub_query.rb', line 5 def query @query end |
Instance Method Details
#execute!(data = []) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sql_query_executor/query/sub_query.rb', line 16 def execute!(data=[]) return [] unless @children result = [] @children.each do |child| result = child.execute!(result) end result = data.send(@binding_operator, result) if @binding_operator && (data && !data.empty?) result.sort_by(&:id) end |