Class: SqlQueryExecutor::Query::Sentence

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_operatorObject (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

#operatorObject (readonly)

Returns the value of attribute operator.



9
10
11
# File 'lib/sql_query_executor/query/sentence.rb', line 9

def operator
  @operator
end

#queryObject (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