aboutsummaryrefslogblamecommitdiffstats
path: root/activemodel/lib/active_model/type/immutable_string.rb
blob: 58268540e5a42a5c4244dd915e4c8f30957a3c52 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                               

                           





                  
                             

                      

                               

                           

                       


       
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