Class: Babik::Selection::Operation::IfNotNullOperation

Inherits:
Base
  • Object
show all
Defined in:
lib/babik/queryset/lib/selection/operation/operations.rb

Overview

Operations that in case a nil is passed will convert the equality comparison to IS NULL

Direct Known Subclasses

Equal, Exact

Constant Summary collapse

SQL_OPERATOR =
'='

Instance Attribute Summary

Attributes inherited from Base

#field, #sql_operation, #sql_operation_template, #value

Instance Method Summary collapse

Methods inherited from Base

#_init_sql_operation, date_special_cases, #db_engine, escape, factory, initialize_operation, initialize_operators, operator?, special_cases, #to_s

Constructor Details

#initialize(field, value) ⇒ IfNotNullOperation

Returns a new instance of IfNotNullOperation.



20
21
22
23
24
25
26
# File 'lib/babik/queryset/lib/selection/operation/operations.rb', line 20

def initialize(field, value)
  if value.nil?
    super(field, '?field IS NULL', value)
  else
    super(field, "?field #{SQL_OPERATOR} ?value", value)
  end
end