Class: ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date

Inherits:
Type::Date show all
Defined in:
activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ActiveModel::Type::Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods included from Type::Internal::Timezone

#default_timezone, #is_utc?

Methods inherited from ActiveModel::Type::Date

#type, #type_cast_for_schema

Methods included from ActiveModel::Type::Helpers::Timezone

#default_timezone, #is_utc?

Methods inherited from ActiveModel::Type::Value

#==, #assert_valid_value, #binary?, #cast, #changed?, #changed_in_place?, #deserialize, #force_equality?, #hash, #initialize, #map, #serialize, #type, #type_cast_for_schema, #value_constructed_by_mass_assignment?

Constructor Details

This class inherits a constructor from ActiveModel::Type::Value

Instance Method Details

#cast_value(value) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
# File 'activerecord/lib/active_record/connection_adapters/postgresql/oid/date.rb', line 8

def cast_value(value)
  case value
  when "infinity" then ::Float::INFINITY
  when "-infinity" then -::Float::INFINITY
  when / BC$/
    astronomical_year = format("%04d", -value[/^\d+/].to_i + 1)
    super(value.sub(/ BC$/, "").sub(/^\d+/, astronomical_year))
  else
    super
  end
end