Class: ActiveRecord::Normalization::NormalizedValueType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Includes:
ActiveModel::Type::SerializeCastValue
Defined in:
lib/active_record/normalization.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cast_type:, normalizer:, normalize_nil:) ⇒ NormalizedValueType

Returns a new instance of NormalizedValueType.



124
125
126
127
128
129
# File 'lib/active_record/normalization.rb', line 124

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_typeObject (readonly)

Returns the value of attribute cast_type.



121
122
123
# File 'lib/active_record/normalization.rb', line 121

def cast_type
  @cast_type
end

#normalize_nilObject (readonly) Also known as: normalize_nil?

Returns the value of attribute normalize_nil.



121
122
123
# File 'lib/active_record/normalization.rb', line 121

def normalize_nil
  @normalize_nil
end

#normalizerObject (readonly)

Returns the value of attribute normalizer.



121
122
123
# File 'lib/active_record/normalization.rb', line 121

def normalizer
  @normalizer
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



143
144
145
146
147
148
# File 'lib/active_record/normalization.rb', line 143

def ==(other)
  self.class == other.class &&
    normalize_nil? == other.normalize_nil? &&
    normalizer == other.normalizer &&
    cast_type == other.cast_type
end

#cast(value) ⇒ Object



131
132
133
# File 'lib/active_record/normalization.rb', line 131

def cast(value)
  normalize(super(value))
end

#hashObject



151
152
153
# File 'lib/active_record/normalization.rb', line 151

def hash
  [self.class, cast_type, normalizer, normalize_nil?].hash
end

#serialize(value) ⇒ Object



135
136
137
# File 'lib/active_record/normalization.rb', line 135

def serialize(value)
  serialize_cast_value(cast(value))
end

#serialize_cast_value(value) ⇒ Object



139
140
141
# File 'lib/active_record/normalization.rb', line 139

def serialize_cast_value(value)
  ActiveModel::Type::SerializeCastValue.serialize(cast_type, value)
end