Sha256: 00fecdb02f1e78be0e024aeed7184b1b66729a3f246b1590826490ac567e5875

Contents?: true

Size: 773 Bytes

Versions: 4

Compression:

Stored size: 773 Bytes

Contents

module ActiveRecord
  module Type
    class String < Value # :nodoc:
      def type
        :string
      end

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

      def type_cast_for_database(value)
        case value
        when ::Numeric, ActiveSupport::Duration then value.to_s
        when ::String then ::String.new(value)
        when true then "1"
        when false then "0"
        else super
        end
      end

      private

      def cast_value(value)
        case value
        when true then "1"
        when false then "0"
        # String.new is slightly faster than dup
        else ::String.new(value.to_s)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activerecord-4.2.0.beta4 lib/active_record/type/string.rb
activerecord-4.2.0.beta3 lib/active_record/type/string.rb
activerecord-4.2.0.beta2 lib/active_record/type/string.rb
activerecord-4.2.0.beta1 lib/active_record/type/string.rb