Sha256: 5aba3306aa8bba0c28f1947a93277ea0a36419c7d93fe69bc3de120005c21b65

Contents?: true

Size: 1.12 KB

Versions: 42

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

require "active_model/type/immutable_string"

module ActiveModel
  module Type
    # = 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.
    class String < ImmutableString
      def changed_in_place?(raw_old_value, new_value)
        if new_value.is_a?(::String)
          raw_old_value != new_value
        end
      end

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

      private
        def cast_value(value)
          case value
          when ::String then ::String.new(value)
          when true then @true
          when false then @false
          else value.to_s
          end
        end
    end
  end
end

Version data entries

42 entries across 42 versions & 6 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activemodel-7.1.3.4/lib/active_model/type/string.rb
activemodel-8.0.1 lib/active_model/type/string.rb
activemodel-8.0.0.1 lib/active_model/type/string.rb
activemodel-7.2.2.1 lib/active_model/type/string.rb
activemodel-7.1.5.1 lib/active_model/type/string.rb
activemodel-8.0.0 lib/active_model/type/string.rb
activemodel-7.2.2 lib/active_model/type/string.rb
activemodel-7.1.5 lib/active_model/type/string.rb
activemodel-8.0.0.rc2 lib/active_model/type/string.rb
activemodel-7.2.1.2 lib/active_model/type/string.rb
activemodel-7.1.4.2 lib/active_model/type/string.rb
activemodel-8.0.0.rc1 lib/active_model/type/string.rb
activemodel-7.2.1.1 lib/active_model/type/string.rb
activemodel-7.1.4.1 lib/active_model/type/string.rb
activemodel-8.0.0.beta1 lib/active_model/type/string.rb
omg-activemodel-8.0.0.alpha9 lib/active_model/type/string.rb
omg-activemodel-8.0.0.alpha8 lib/active_model/type/string.rb
omg-activemodel-8.0.0.alpha7 lib/active_model/type/string.rb
omg-activemodel-8.0.0.alpha4 lib/active_model/type/string.rb
omg-activemodel-8.0.0.alpha3 lib/active_model/type/string.rb