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 inherited from ActiveModel::Type::Value
#as_json, #assert_valid_value, #binary?, #changed?, #changed_in_place?, #deserialize, #force_equality?, #immutable_value, #map, #serializable?, #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.
114 115 116 117 118 119 |
# File 'activerecord/lib/active_record/normalization.rb', line 114 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
111 112 113 |
# File 'activerecord/lib/active_record/normalization.rb', line 111 def cast_type @cast_type end |
#normalize_nil ⇒ Object (readonly) Also known as: normalize_nil?
Returns the value of attribute normalize_nil
111 112 113 |
# File 'activerecord/lib/active_record/normalization.rb', line 111 def normalize_nil @normalize_nil end |
#normalizer ⇒ Object (readonly)
Returns the value of attribute normalizer
111 112 113 |
# File 'activerecord/lib/active_record/normalization.rb', line 111 def normalizer @normalizer end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
133 134 135 136 137 138 |
# File 'activerecord/lib/active_record/normalization.rb', line 133 def ==(other) self.class == other.class && normalize_nil? == other.normalize_nil? && normalizer == other.normalizer && cast_type == other.cast_type end |
#cast(value) ⇒ Object
121 122 123 |
# File 'activerecord/lib/active_record/normalization.rb', line 121 def cast(value) normalize(super(value)) end |
#hash ⇒ Object
141 142 143 |
# File 'activerecord/lib/active_record/normalization.rb', line 141 def hash [self.class, cast_type, normalizer, normalize_nil?].hash end |
#inspect ⇒ Object
145 146 147 |
# File 'activerecord/lib/active_record/normalization.rb', line 145 def inspect Kernel.instance_method(:inspect).bind_call(self) end |
#serialize(value) ⇒ Object
125 126 127 |
# File 'activerecord/lib/active_record/normalization.rb', line 125 def serialize(value) serialize_cast_value(cast(value)) end |
#serialize_cast_value(value) ⇒ Object
129 130 131 |
# File 'activerecord/lib/active_record/normalization.rb', line 129 def serialize_cast_value(value) ActiveModel::Type::SerializeCastValue.serialize(cast_type, value) end |