Class: ActiveModel::Attributes::Normalization::NormalizedValueType
- Inherits:
-
Type::Value
- Object
- Type::Value
- ActiveModel::Attributes::Normalization::NormalizedValueType
- Includes:
- Type::SerializeCastValue
- Defined in:
- lib/active_model/attributes/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 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.
- #serialize(value) ⇒ Object
- #serialize_cast_value(value) ⇒ Object
Methods included from Type::SerializeCastValue
included, #itself_if_serialize_cast_value_compatible, serialize
Methods inherited from 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.
152 153 154 155 156 157 |
# File 'lib/active_model/attributes/normalization.rb', line 152 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.
149 150 151 |
# File 'lib/active_model/attributes/normalization.rb', line 149 def cast_type @cast_type end |
#normalize_nil ⇒ Object (readonly) Also known as: normalize_nil?
Returns the value of attribute normalize_nil.
149 150 151 |
# File 'lib/active_model/attributes/normalization.rb', line 149 def normalize_nil @normalize_nil end |
#normalizer ⇒ Object (readonly)
Returns the value of attribute normalizer.
149 150 151 |
# File 'lib/active_model/attributes/normalization.rb', line 149 def normalizer @normalizer end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
171 172 173 174 175 176 |
# File 'lib/active_model/attributes/normalization.rb', line 171 def ==(other) self.class == other.class && normalize_nil? == other.normalize_nil? && normalizer == other.normalizer && cast_type == other.cast_type end |
#cast(value) ⇒ Object
159 160 161 |
# File 'lib/active_model/attributes/normalization.rb', line 159 def cast(value) normalize(super(value)) end |
#hash ⇒ Object
179 180 181 |
# File 'lib/active_model/attributes/normalization.rb', line 179 def hash [self.class, cast_type, normalizer, normalize_nil?].hash end |
#serialize(value) ⇒ Object
163 164 165 |
# File 'lib/active_model/attributes/normalization.rb', line 163 def serialize(value) serialize_cast_value(cast(value)) end |
#serialize_cast_value(value) ⇒ Object
167 168 169 |
# File 'lib/active_model/attributes/normalization.rb', line 167 def serialize_cast_value(value) ActiveModel::Type::SerializeCastValue.serialize(cast_type, value) end |