Class: ActiveRecord::Normalization::NormalizedValueType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- ActiveRecord::Normalization::NormalizedValueType
- Includes:
- ActiveModel::Type::SerializeCastValue
- Defined in:
- activerecord/lib/active_record/normalization.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#cast_type ⇒ Object
readonly
Returns the value of attribute cast_type.
-
#normalize_nil ⇒ Object
(also: #normalize_nil?)
readonly
Returns the value of attribute normalize_nil.
-
#normalizer ⇒ Object
readonly
Returns the value of attribute normalizer.
Attributes inherited from ActiveModel::Type::Value
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #cast(value) ⇒ Object
- #hash ⇒ Object
-
#initialize(cast_type:, normalizer:, normalize_nil:) ⇒ NormalizedValueType
constructor
A new instance of NormalizedValueType.
- #inspect ⇒ Object
- #serialize(value) ⇒ Object
- #serialize_cast_value(value) ⇒ Object
Methods included from ActiveModel::Type::SerializeCastValue
included, #itself_if_serialize_cast_value_compatible, serialize
Methods included from ActiveSupport::Concern
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
Methods inherited from ActiveModel::Type::Value
#as_json, #assert_valid_value, #binary?, #changed?, #changed_in_place?, #deserialize, #force_equality?, #map, #mutable?, #serializable?, #serialized?, #type, #type_cast_for_schema, #value_constructed_by_mass_assignment?
Constructor Details
#initialize(cast_type:, normalizer:, normalize_nil:) ⇒ NormalizedValueType
Returns a new instance of NormalizedValueType.
118 119 120 121 122 123 |
# File 'activerecord/lib/active_record/normalization.rb', line 118 def initialize(cast_type:, normalizer:, normalize_nil:) @cast_type = cast_type @normalizer = normalizer @normalize_nil = normalize_nil super(cast_type) end |
Instance Attribute Details
#cast_type ⇒ Object (readonly)
Returns the value of attribute cast_type.
115 116 117 |
# File 'activerecord/lib/active_record/normalization.rb', line 115 def cast_type @cast_type end |
#normalize_nil ⇒ Object (readonly) Also known as: normalize_nil?
Returns the value of attribute normalize_nil.
115 116 117 |
# File 'activerecord/lib/active_record/normalization.rb', line 115 def normalize_nil @normalize_nil end |
#normalizer ⇒ Object (readonly)
Returns the value of attribute normalizer.
115 116 117 |
# File 'activerecord/lib/active_record/normalization.rb', line 115 def normalizer @normalizer end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
137 138 139 140 141 142 |
# File 'activerecord/lib/active_record/normalization.rb', line 137 def ==(other) self.class == other.class && normalize_nil? == other.normalize_nil? && normalizer == other.normalizer && cast_type == other.cast_type end |
#cast(value) ⇒ Object
125 126 127 |
# File 'activerecord/lib/active_record/normalization.rb', line 125 def cast(value) normalize(super(value)) end |
#hash ⇒ Object
145 146 147 |
# File 'activerecord/lib/active_record/normalization.rb', line 145 def hash [self.class, cast_type, normalizer, normalize_nil?].hash end |
#inspect ⇒ Object
149 150 151 |
# File 'activerecord/lib/active_record/normalization.rb', line 149 def inspect Kernel.instance_method(:inspect).bind_call(self) end |
#serialize(value) ⇒ Object
129 130 131 |
# File 'activerecord/lib/active_record/normalization.rb', line 129 def serialize(value) serialize_cast_value(cast(value)) end |
#serialize_cast_value(value) ⇒ Object
133 134 135 |
# File 'activerecord/lib/active_record/normalization.rb', line 133 def serialize_cast_value(value) ActiveModel::Type::SerializeCastValue.serialize(cast_type, value) end |