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.



117
118
119
120
121
122
# File 'lib/active_record/normalization.rb', line 117

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.



114
115
116
# File 'lib/active_record/normalization.rb', line 114

def cast_type
  @cast_type
end

#normalize_nilObject (readonly) Also known as: normalize_nil?

Returns the value of attribute normalize_nil.



114
115
116
# File 'lib/active_record/normalization.rb', line 114

def normalize_nil
  @normalize_nil
end

#normalizerObject (readonly)

Returns the value of attribute normalizer.



114
115
116
# File 'lib/active_record/normalization.rb', line 114

def normalizer
  @normalizer
end

Instance Method Details

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



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

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

#cast(value) ⇒ Object



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

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

#hashObject



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

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

#inspectObject



148
149
150
# File 'lib/active_record/normalization.rb', line 148

def inspect
  Kernel.instance_method(:inspect).bind_call(self)
end

#serialize(value) ⇒ Object



128
129
130
# File 'lib/active_record/normalization.rb', line 128

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

#serialize_cast_value(value) ⇒ Object



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

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