Class: Babik::Selection::Operation::DateOperation

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

Overview

Each one of the operations over date fields (date, year, month, day, etc.)

Direct Known Subclasses

Day, Hour, Minute, Month, Quarter, Second, Time, Week, WeekDay, Year

Constant Summary collapse

HAS_OPERATOR =
true

Constants included from ValidDBMS

ValidDBMS::SUPPORTED_DB_ADAPTERS

Instance Attribute Summary

Attributes inherited from Base

#field, #sql_operation, #sql_operation_template, #value

Instance Method Summary collapse

Methods included from ValidDBMS

#assert_dbms

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, operator, value) ⇒ DateOperation

Returns a new instance of DateOperation.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 24

def initialize(field, operator, value)
  assert_dbms
  operator ||= 'equal'
  @operator = operator
  # In the left-hand of the main operator lies the sql_function
  # that will extract the desired part of the datetime
  # This function represents the field as #field, not as ?field
  # to avoid having replacement issues
  code_for_sql_function = sql_function
  main_operation = Base.factory(code_for_sql_function, operator, value)
  # Replacement mechanism only understand ?field and not #field,
  # so replace #field for ?field and let it work
  main_operation_sql_code = main_operation.sql_operation.sub('#field', '?field')
  super(field, main_operation_sql_code, value)
end

Instance Method Details

#sql_functionObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 40

def sql_function
  raise NotImplementedError
end