lib/chrono_model/adapter/tsrange.rb in chrono_model-1.2.2 vs lib/chrono_model/adapter/tsrange.rb in chrono_model-2.0.0
- old
+ new
@@ -1,8 +1,9 @@
+# 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:
@@ -24,20 +25,35 @@
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 ]
+ 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: (value[1] == ',' || from == '-infinity') ? nil : from[1..-2],
- to: (value[-2] == ',' || to == 'infinity') ? nil : to[1..-2],
+ from: from_bound,
+ to: to_bound
}
end
end
def initialize_type_map(m = type_map)
@@ -50,8 +66,7 @@
type_map.register_type oid, cm_type
end
end
end
-
end
end