Module: Trax::Model::ExtensionsFor::StructFields::Time::ClassMethods
- Defined in:
- lib/trax/model/extensions_for/struct_fields/time.rb
Instance Method Summary collapse
- #after(value) ⇒ Object
- #before(value) ⇒ Object
- #between(first_time, second_time) ⇒ Object
- #gt(value) ⇒ Object
- #gte(value) ⇒ Object
- #in_range(first_time, second_time) ⇒ Object
- #lt(value) ⇒ Object
- #lte(value) ⇒ Object
Instance Method Details
#after(value) ⇒ Object
10 11 12 13 14 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 10 def after(value) cast_type = 'timestamp' operator = '>' model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value) end |
#before(value) ⇒ Object
16 17 18 19 20 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 16 def before(value) cast_type = 'timestamp' operator = '<' model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value) end |
#between(first_time, second_time) ⇒ Object
22 23 24 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 22 def between(first_time, second_time) after(first_time).merge(before(second_time)) end |
#gt(value) ⇒ Object
26 27 28 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 26 def gt(value) after(value) end |
#gte(value) ⇒ Object
30 31 32 33 34 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 30 def gte(value) cast_type = 'timestamp' operator = '>=' model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value) end |
#in_range(first_time, second_time) ⇒ Object
36 37 38 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 36 def in_range(first_time, second_time) gte(first_time).merge(lte(second_time)) end |
#lt(value) ⇒ Object
40 41 42 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 40 def lt(value) before(value) end |
#lte(value) ⇒ Object
44 45 46 47 48 |
# File 'lib/trax/model/extensions_for/struct_fields/time.rb', line 44 def lte(value) cast_type = 'timestamp' operator = '<=' model_class.where("(#{parent_definition.field_name} ->> '#{field_name}')::#{cast_type} #{operator} ?", value) end |