Class: Babik::Selection::Operation::In
- Defined in:
- lib/babik/queryset/lib/selection/operation/operations.rb
Overview
IN operation
Instance Attribute Summary
Attributes inherited from Base
#field, #sql_operation, #sql_operation_template, #value
Instance Method Summary collapse
- #_init_sql_operation ⇒ Object
- #_init_value(value) ⇒ Object
-
#initialize(field, value) ⇒ In
constructor
A new instance of In.
Methods inherited from Base
date_special_cases, #db_engine, escape, factory, initialize_operation, initialize_operators, operator?, special_cases, #to_s
Constructor Details
#initialize(field, value) ⇒ In
Returns a new instance of In.
46 47 48 49 |
# File 'lib/babik/queryset/lib/selection/operation/operations.rb', line 46 def initialize(field, value) _init_value(value) super(field, '?field IN ?value', @value) end |
Instance Method Details
#_init_sql_operation ⇒ Object
72 73 74 |
# File 'lib/babik/queryset/lib/selection/operation/operations.rb', line 72 def _init_sql_operation @sql_operation = @sql_operation_template.sub('?field', @field).sub('?value', @value) end |
#_init_value(value) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/babik/queryset/lib/selection/operation/operations.rb', line 51 def _init_value(value) if value.class == Array values = value.map do |value_i| if value_i.is_a?(String) self.class.escape(value_i) elsif value_i.is_a?(ActiveRecord::Base) value_i.id else value_i end end @value = "(#{values.join(', ')})" elsif value.class == Babik::QuerySet::Base @value = "(#{value.sql.select})" elsif value.class == String @value = "('#{self.class.escape(value)}')" else @value = "(#{value})" end end |