Sha256: 2fc5002d38863050387d2dbee13c49b01afce46a263e7ec85f8204c92990eb59

Contents?: true

Size: 576 Bytes

Versions: 22

Compression:

Stored size: 576 Bytes

Contents

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

22 entries across 22 versions & 2 rubygems

Version Path
activemodel-5.1.0.rc1 lib/active_model/type/immutable_string.rb
activemodel-5.1.0.beta1 lib/active_model/type/immutable_string.rb