Class: Cassanity::ArgumentGenerators::WhereClause
- Inherits:
-
Object
- Object
- Cassanity::ArgumentGenerators::WhereClause
- Defined in:
- lib/cassanity/argument_generators/where_clause.rb
Instance Method Summary collapse
-
#call(args = {}) ⇒ Object
Internal.
Instance Method Details
#call(args = {}) ⇒ Object
Internal
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cassanity/argument_generators/where_clause.rb', line 14 def call(args = {}) where = args[:where] cql = '' return [cql] if where.nil? || where.empty? variables, wheres = [], [] where.each do |key, value| case value when Array wheres << "#{key} IN (?)" variables << value when Range start, finish = value.begin, value.end end_operator = value.exclude_end? ? '<' : '<=' wheres << "#{key} >= ?" wheres << "#{key} #{end_operator} ?" variables << start variables << finish when Cassanity::Operator wheres << "#{key} #{value.symbol} ?" variables << value.value else wheres << "\"#{key}\" = ?" variables << value end end cql << " WHERE #{wheres.join(' AND ')}" [cql, *variables] end |