Class: ChronoModel::Adapter::TSRange::Type
- Inherits:
-
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range
- ChronoModel::Adapter::TSRange::Type
- Defined in:
- lib/chrono_model/adapter/tsrange.rb
Overview
HACK: Redefine tsrange parsing support, as it is broken currently.
This self-made API is here because currently AR4 does not support open-ended ranges. The reasons are poor support in Ruby:
https://bugs.ruby-lang.org/issues/6864
and an instable interface in Active Record:
https://github.com/rails/rails/issues/13793
https://github.com/rails/rails/issues/14010
so, for now, we are implementing our own.
Constant Summary collapse
- OID =
3908
Instance Method Summary collapse
Instance Method Details
#cast_value(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/chrono_model/adapter/tsrange.rb', line 22 def cast_value(value) return if value == 'empty' return value if value.is_a?(::Array) extracted = extract_bounds(value) from = Conversions.string_to_utc_time extracted[:from] to = Conversions.string_to_utc_time extracted[:to ] [from, to] end |
#extract_bounds(value) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/chrono_model/adapter/tsrange.rb', line 34 def extract_bounds(value) from, to = value[1..-2].split(',') { from: (value[1] == ',' || from == '-infinity') ? nil : from[1..-2], to: (value[-2] == ',' || to == 'infinity') ? nil : to[1..-2], } end |