Sha256: dde57bd13fd15d7c9705942f8f5ebf13f2e7a259c5e0207d317b50d516126503

Contents?: true

Size: 813 Bytes

Versions: 44

Compression:

Stored size: 813 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 "t"
        when false then "f"
        else super
        end
      end

      def text?
        true
      end

      private

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

Version data entries

44 entries across 43 versions & 8 rubygems

Version Path
activerecord-4.2.11.3 lib/active_record/type/string.rb
activerecord-4.2.11.2 lib/active_record/type/string.rb
activerecord-4.2.11.1 lib/active_record/type/string.rb
activerecord-4.2.11 lib/active_record/type/string.rb
activerecord-4.2.10 lib/active_record/type/string.rb
activerecord-4.2.10.rc1 lib/active_record/type/string.rb
activerecord-4.2.9 lib/active_record/type/string.rb
activerecord-4.2.9.rc2 lib/active_record/type/string.rb
activerecord-4.2.9.rc1 lib/active_record/type/string.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-4.2.8/lib/active_record/type/string.rb
activerecord-4.2.8 lib/active_record/type/string.rb
activerecord-4.2.8.rc1 lib/active_record/type/string.rb
activerecord-4.2.7.1 lib/active_record/type/string.rb
activerecord-4.2.7 lib/active_record/type/string.rb
activerecord-4.2.7.rc1 lib/active_record/type/string.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/type/string.rb
activerecord-4.2.6 lib/active_record/type/string.rb
activerecord-4.2.6.rc1 lib/active_record/type/string.rb
activerecord-4.2.5.2 lib/active_record/type/string.rb
activejob-lock-0.0.2 rails/activerecord/lib/active_record/type/string.rb