Class: ActiveRecord::Type::String

Inherits:
Value show all
Defined in:
activerecord/lib/active_record/type/string.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from Value

#==, #binary?, #changed?, #hash, #initialize, #klass, #number?, #type_cast_for_schema, #type_cast_from_database, #type_cast_from_user

Constructor Details

This class inherits a constructor from ActiveRecord::Type::Value

Instance Method Details

#changed_in_place?(raw_old_value, new_value) ⇒ Boolean

Returns:


8
9
10
11
12
# File 'activerecord/lib/active_record/type/string.rb', line 8

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

#text?Boolean

Returns:


24
25
26
# File 'activerecord/lib/active_record/type/string.rb', line 24

def text?
  true
end

#typeObject


4
5
6
# File 'activerecord/lib/active_record/type/string.rb', line 4

def type
  :string
end

#type_cast_for_database(value) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'activerecord/lib/active_record/type/string.rb', line 14

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