Module: ActiveRecord::ConnectionAdapters::CockroachDB::OID::Interval

Defined in:
lib/active_record/connection_adapters/cockroachdb/oid/interval.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_PRECISION =

microseconds

6

Instance Method Summary collapse

Instance Method Details

#cast_value(value) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_record/connection_adapters/cockroachdb/oid/interval.rb', line 28

def cast_value(value)
  case value
  when ::ActiveSupport::Duration
    value
  when ::String
    begin
      PostgresqlInterval::Parser.parse(value)
    rescue PostgresqlInterval::ParseError
      # Try ISO 8601
      super
    end
  else
    super
  end
end

#serialize(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_record/connection_adapters/cockroachdb/oid/interval.rb', line 44

def serialize(value)
  precision = self.precision || DEFAULT_PRECISION
  case value
  when ::ActiveSupport::Duration
    serialize_duration(value, precision)
  when ::Numeric
    serialize_duration(value.seconds, precision)
  else
    super
  end
end

#type_cast_for_schema(value) ⇒ Object



56
57
58
# File 'lib/active_record/connection_adapters/cockroachdb/oid/interval.rb', line 56

def type_cast_for_schema(value)
  serialize(value).inspect
end