Class: Babik::Selection::Operation::Month
- Inherits:
-
DateOperation
- Object
- Base
- DateOperation
- Babik::Selection::Operation::Month
- Defined in:
- lib/babik/queryset/lib/selection/operation/date.rb
Overview
Month date operation
Constant Summary
Constants inherited from DateOperation
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
-
#initialize(field, operator, value) ⇒ Month
constructor
A new instance of Month.
- #sql_function ⇒ Object
Methods included from ValidDBMS
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) ⇒ Month
Returns a new instance of Month.
69 70 71 72 |
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 69 def initialize(field, operator, value) value = format('%02d', value) if db_engine == 'sqlite3' super(field, operator, value) end |
Instance Method Details
#sql_function ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 74 def sql_function dbms_adapter = db_engine return 'MONTH(#field)' if dbms_adapter == 'mysql2' return 'EXTRACT(MONTH FROM #field)' if dbms_adapter == 'postgresql' return 'strftime(\'%m\', #field)' if dbms_adapter == 'sqlite3' raise NotImplementedError, "#{self.class} lookup not implemented for #{dbms_adapter}" end |