Class: ActiveModel::Type::String

Inherits:
ImmutableString show all
Defined in:
activemodel/lib/active_model/type/string.rb

Overview

Active Model String Type

Attribute type for strings. It is registered under the :string key.

This class is a specialization of ActiveModel::Type::ImmutableString. It performs coercion in the same way, and can be configured in the same way. However, it accounts for mutable strings, so dirty tracking can properly check if a string has changed.

Direct Known Subclasses

ActiveRecord::Type::Text

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from ImmutableString

#initialize, #serialize, #serialize_cast_value, #type

Methods inherited from Value

#==, #as_json, #assert_valid_value, #binary?, #cast, #changed?, #deserialize, #force_equality?, #hash, #initialize, #map, #mutable?, #serializable?, #serialize, #serialized?, #type, #type_cast_for_schema, #value_constructed_by_mass_assignment?

Methods included from SerializeCastValue

included, #initialize, #itself_if_serialize_cast_value_compatible, serialize

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Constructor Details

This class inherits a constructor from ActiveModel::Type::ImmutableString

Instance Method Details

#changed_in_place?(raw_old_value, new_value) ⇒ Boolean

Returns:



16
17
18
19
20
# File 'activemodel/lib/active_model/type/string.rb', line 16

def changed_in_place?(raw_old_value, new_value)
  if new_value.is_a?(::String)
    raw_old_value != new_value
  end
end

#to_immutable_stringObject



22
23
24
25
26
27
28
29
30
# File 'activemodel/lib/active_model/type/string.rb', line 22

def to_immutable_string
  ImmutableString.new(
    true: @true,
    false: @false,
    limit: limit,
    precision: precision,
    scale: scale,
  )
end