123456789_123456789_123456789_123456789_123456789_

Module: ActiveModel::Type::SerializeCastValue

Do not use. This module is for internal use only.
Relationships & Source Files
Namespace Children
Modules:
Extension / Inclusion / Inheritance Descendants
Included In:
BigInteger, Binary, Boolean, Date, DateTime, Decimal, Float, ImmutableString, Integer, String, Time, Value, ::ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bit, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::BitVarying, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Bytea, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Cidr, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Date, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::DateTime, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Decimal, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Enum, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Hstore, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Inet, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Interval, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::LegacyPoint, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Macaddr, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Money, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Oid, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Point, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Range, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::SpecializedString, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Timestamp, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::TimestampWithTimeZone, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Vector, ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Xml, ::ActiveRecord::ConnectionAdapters::SQLite3Adapter::SQLite3Integer, ::ActiveRecord::Encryption::EncryptedAttributeType, ::ActiveRecord::Locking::LockingType, ::ActiveRecord::Normalization::NormalizedValueType, ::ActiveRecord::Type::Date, ::ActiveRecord::Type::DateTime, ::ActiveRecord::Type::DecimalWithoutScale, ::ActiveRecord::Type::Json, ::ActiveRecord::Type::Serialized, ::ActiveRecord::Type::Text, ::ActiveRecord::Type::Time, ::ActiveRecord::Type::UnsignedInteger
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: activemodel/lib/active_model/type/serialize_cast_value.rb

Class Method Summary

::ActiveSupport::Concern - Extended

class_methods

Define class methods from given block.

included

Evaluate given block in context of base class, so that you can write class macros here.

prepended

Evaluate given block in context of base class, so that you can write class macros here.

append_features, prepend_features

Instance Method Summary

Class Method Details

.included(klass)

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/serialize_cast_value.rb', line 21

def self.included(klass)
  klass.include DefaultImplementation unless klass.method_defined?(:serialize_cast_value)
end

.serialize(type, value)

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/serialize_cast_value.rb', line 25

def self.serialize(type, value)
  # Using `type.equal?(type.itself_if_...)` is a performant way to also
  # ensure that `type` is not just a DelegateClass instance (e.g.
  # ActiveRecord::Type::Serialized) unintentionally delegating
  # SerializeCastValue methods.
  if type.equal?((type.itself_if_serialize_cast_value_compatible rescue nil))
    type.serialize_cast_value(value)
  else
    type.serialize(value)
  end
end

Instance Method Details

#initialize

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/serialize_cast_value.rb', line 41

def initialize(...)
  super
  self.class.serialize_cast_value_compatible? # eagerly compute
end

#itself_if_serialize_cast_value_compatible

[ GitHub ]

  
# File 'activemodel/lib/active_model/type/serialize_cast_value.rb', line 37

def itself_if_serialize_cast_value_compatible
  self if self.class.serialize_cast_value_compatible?
end