Class: ChronoModel::Adapter::TSRange

Inherits:
OID::Type
  • Object
show all
Defined in:
lib/chrono_model/adapter.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.

Instance Method Summary collapse

Instance Method Details

#extract_bounds(value) ⇒ Object



472
473
474
475
476
477
478
479
480
# File 'lib/chrono_model/adapter.rb', line 472

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],
    #exclude_start: (value[0] == '('),
    #exclude_end:   (value[-1] == ')')
  }
end

#type_cast(value) ⇒ Object



482
483
484
485
486
487
488
489
# File 'lib/chrono_model/adapter.rb', line 482

def type_cast(value)
  extracted = extract_bounds(value)

  from = Conversions.string_to_utc_time extracted[:from]
  to   = Conversions.string_to_utc_time extracted[:to  ]

  [from, to]
end