Sha256: c77830deeddc2ab22f2b8f043b0fba57924a838d0d7199649420f811390c12d3

Contents?: true

Size: 607 Bytes

Versions: 53

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true

module ActiveModel
  module Type
    class ImmutableString < Value # :nodoc:
      def type
        :string
      end

      def serialize(value)
        case value
        when ::Numeric, ActiveSupport::Duration then value.to_s
        when true then "t"
        when false then "f"
        else super
        end
      end

      private

        def cast_value(value)
          result = \
            case value
            when true then "t"
            when false then "f"
            else value.to_s
            end
          result.freeze
        end
    end
  end
end

Version data entries

53 entries across 53 versions & 8 rubygems

Version Path
activemodel-5.2.8.1 lib/active_model/type/immutable_string.rb
activemodel-5.2.8 lib/active_model/type/immutable_string.rb
activemodel-5.2.7.1 lib/active_model/type/immutable_string.rb
activemodel-5.2.7 lib/active_model/type/immutable_string.rb
activemodel-5.2.6.3 lib/active_model/type/immutable_string.rb
activemodel-5.2.6.2 lib/active_model/type/immutable_string.rb
activemodel-5.2.6.1 lib/active_model/type/immutable_string.rb
activemodel-5.2.6 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.6 lib/active_model/type/immutable_string.rb
activemodel-5.2.5 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.5 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.4 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.3 lib/active_model/type/immutable_string.rb
activemodel-6.0.2.2 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.2 lib/active_model/type/immutable_string.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/type/immutable_string.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/activemodel-6.0.2.1/lib/active_model/type/immutable_string.rb
activemodel-6.0.2.1 lib/active_model/type/immutable_string.rb
activemodel-5.2.4.1 lib/active_model/type/immutable_string.rb
activemodel-6.0.2 lib/active_model/type/immutable_string.rb