Class: SqlQueryExecutor::Query::Sentence
- Inherits:
-
Object
- Object
- SqlQueryExecutor::Query::Sentence
- Defined in:
- lib/sql_query_executor/query/sentence.rb
Constant Summary collapse
- OPERATORS =
{ "between" => SqlQueryExecutor::Operators::Between, "is" => SqlQueryExecutor::Operators::Is, "in" => SqlQueryExecutor::Operators::In, "=" => SqlQueryExecutor::Operators::Default, ">" => SqlQueryExecutor::Operators::Default, "<" => SqlQueryExecutor::Operators::Default, ">=" => SqlQueryExecutor::Operators::Default, "<=" => SqlQueryExecutor::Operators::Default, "<>" => SqlQueryExecutor::Operators::Default, "!=" => SqlQueryExecutor::Operators::Default, "not" => SqlQueryExecutor::Operators::Default, "exists" => SqlQueryExecutor::Operators::Default,#Exists }
- BINDING_OPERATORS =
{ "and" => "&", "or" => "+" }
Instance Attribute Summary collapse
-
#binding_operator ⇒ Object
readonly
Returns the value of attribute binding_operator.
-
#operator ⇒ Object
readonly
Returns the value of attribute operator.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #execute!(data) ⇒ Object
-
#initialize(query, collection) ⇒ Sentence
constructor
A new instance of Sentence.
Constructor Details
#initialize(query, collection) ⇒ Sentence
Returns a new instance of Sentence.
31 32 33 34 35 36 37 38 |
# File 'lib/sql_query_executor/query/sentence.rb', line 31 def initialize(query, collection) @query = query @collection = collection @array = query.split(' ') set_binding_operator set_operator end |
Instance Attribute Details
#binding_operator ⇒ Object (readonly)
Returns the value of attribute binding_operator.
9 10 11 |
# File 'lib/sql_query_executor/query/sentence.rb', line 9 def binding_operator @binding_operator end |
#operator ⇒ Object (readonly)
Returns the value of attribute operator.
9 10 11 |
# File 'lib/sql_query_executor/query/sentence.rb', line 9 def operator @operator end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
9 10 11 |
# File 'lib/sql_query_executor/query/sentence.rb', line 9 def query @query end |
Instance Method Details
#execute!(data) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/sql_query_executor/query/sentence.rb', line 40 def execute!(data) return [] unless @operator result = @operator.execute!(data) result = data.send(@binding_operator, result) if @binding_operator && (data && !data.empty?) result end |