diff --git a/lib/chrono_model/adapter.rb b/lib/chrono_model/adapter.rb index 8d8aca1..259fe91 100644 --- a/lib/chrono_model/adapter.rb +++ b/lib/chrono_model/adapter.rb @@ -7,7 +7,6 @@ require 'chrono_model/adapter/ddl' require 'chrono_model/adapter/indexes' -require 'chrono_model/adapter/tsrange' require 'chrono_model/adapter/upgrade' module ChronoModel @@ -19,7 +18,6 @@ class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter include ChronoModel::Adapter::Migrations include ChronoModel::Adapter::DDL include ChronoModel::Adapter::Indexes - include ChronoModel::Adapter::TSRange include ChronoModel::Adapter::Upgrade # The schema holding current data diff --git a/lib/chrono_model/adapter/tsrange.rb b/lib/chrono_model/adapter/tsrange.rb deleted file mode 100644 index e005e7f..0000000 --- a/lib/chrono_model/adapter/tsrange.rb +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -module ChronoModel - class Adapter < ActiveRecord::ConnectionAdapters::PostgreSQLAdapter - module TSRange - # 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. - # - class Type < ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range - OID = 3908 - - 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 - - def extract_bounds(value) - from, to = value[1..-2].split(',') - - from_bound = - if value[1] == ',' || from == '-infinity' - nil - else - from[1..-2] - end - - to_bound = - if value[-2] == ',' || to == 'infinity' - nil - else - to[1..-2] - end - - { - from: from_bound, - to: to_bound - } - end - end - - def initialize_type_map(m = type_map) - super.tap do - typ = ChronoModel::Adapter::TSRange::Type - oid = typ::OID - - ar_type = type_map.fetch(oid) - cm_type = typ.new(ar_type.subtype, ar_type.type) - - type_map.register_type oid, cm_type - end - end - end - end -end diff --git a/lib/chrono_model/time_machine/history_model.rb b/lib/chrono_model/time_machine/history_model.rb index b76b2ba..fbdbc6e 100644 --- a/lib/chrono_model/time_machine/history_model.rb +++ b/lib/chrono_model/time_machine/history_model.rb @@ -214,7 +214,7 @@ def valid_from end def valid_to - validity.last + validity.end end alias as_of_time valid_to