Class: ActiveRecord::Normalization::NormalizedValueType
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- ActiveRecord::Normalization::NormalizedValueType
- Includes:
- ActiveModel::Type::SerializeCastValue
- Defined in:
- 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.
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
Constructor Details
#initialize(cast_type:, normalizer:, normalize_nil:) ⇒ NormalizedValueType
Returns a new instance of NormalizedValueType.
126 127 128 129 130 131 |
# File 'lib/active_record/normalization.rb', line 126 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.
123 124 125 |
# File 'lib/active_record/normalization.rb', line 123 def cast_type @cast_type end |
#normalize_nil ⇒ Object (readonly) Also known as: normalize_nil?
Returns the value of attribute normalize_nil.
123 124 125 |
# File 'lib/active_record/normalization.rb', line 123 def normalize_nil @normalize_nil end |
#normalizer ⇒ Object (readonly)
Returns the value of attribute normalizer.
123 124 125 |
# File 'lib/active_record/normalization.rb', line 123 def normalizer @normalizer end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
145 146 147 148 149 150 |
# File 'lib/active_record/normalization.rb', line 145 def ==(other) self.class == other.class && normalize_nil? == other.normalize_nil? && normalizer == other.normalizer && cast_type == other.cast_type end |
#cast(value) ⇒ Object
133 134 135 |
# File 'lib/active_record/normalization.rb', line 133 def cast(value) normalize(super(value)) end |
#hash ⇒ Object
153 154 155 |
# File 'lib/active_record/normalization.rb', line 153 def hash [self.class, cast_type, normalizer, normalize_nil?].hash end |
#inspect ⇒ Object
157 158 159 |
# File 'lib/active_record/normalization.rb', line 157 def inspect Kernel.instance_method(:inspect).bind_call(self) end |
#serialize(value) ⇒ Object
137 138 139 |
# File 'lib/active_record/normalization.rb', line 137 def serialize(value) serialize_cast_value(cast(value)) end |
#serialize_cast_value(value) ⇒ Object
141 142 143 |
# File 'lib/active_record/normalization.rb', line 141 def serialize_cast_value(value) ActiveModel::Type::SerializeCastValue.serialize(cast_type, value) end |