An abstract definition of a column in a table.

Methods
Attributes
[R] default
[R] limit
[R] name
[R] null
[RW] primary
[R] type
Public Class methods
binary_to_string(value)

Used to convert from BLOBs to Strings

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 97
97:       def self.binary_to_string(value)
98:         value
99:       end
new(name, default, sql_type = nil, null = true)

Instantiates a new column in the table.

name is the column’s name, as in supplier_id int(11). default is the type-casted default value, such as sales_stage varchar(20) default ‘new’. sql_type is only used to extract the column’s length, if necessary. For example, company_name varchar(60). null determines if this column allows NULL values.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 16
16:       def initialize(name, default, sql_type = nil, null = true)
17:         @name, @type, @null = name, simplified_type(sql_type), null
18:         # have to do this one separately because type_cast depends on #type
19:         @default = type_cast(default)
20:         @limit   = extract_limit(sql_type) unless sql_type.nil?
21:         @primary = nil
22:         @text    = [:string, :text].include? @type
23:         @number  = [:float, :integer].include? @type
24:       end
string_to_binary(value)

Used to convert from Strings to BLOBs

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 92
92:       def self.string_to_binary(value)
93:         value
94:       end
string_to_date(string)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 101
101:       def self.string_to_date(string)
102:         return string unless string.is_a?(String)
103:         date_array = ParseDate.parsedate(string)
104:         # treat 0000-00-00 as nil
105:         Date.new(date_array[0], date_array[1], date_array[2]) rescue nil
106:       end
string_to_dummy_time(string)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 115
115:       def self.string_to_dummy_time(string)
116:         return string unless string.is_a?(String)
117:         time_array = ParseDate.parsedate(string)
118:         # pad the resulting array with dummy date information
119:         time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1;
120:         Time.send(Base.default_timezone, *time_array) rescue nil
121:       end
string_to_time(string)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 108
108:       def self.string_to_time(string)
109:         return string unless string.is_a?(String)
110:         time_array = ParseDate.parsedate(string)[0..5]
111:         # treat 0000-00-00 00:00:00 as nil
112:         Time.send(Base.default_timezone, *time_array) rescue nil
113:       end
value_to_boolean(value)

convert something to a boolean

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 124
124:       def self.value_to_boolean(value)
125:         return value if value==true || value==false
126:         case value.to_s.downcase
127:         when "true", "t", "1" then true
128:         else false
129:         end
130:       end
Public Instance methods
human_name()

Returns the human name of the column name.

Examples
 Column.new('sales_stage', ...).human_name #=> 'Sales stage'
    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 87
87:       def human_name
88:         Base.human_attribute_name(@name)
89:       end
klass()

Returns the Ruby class that corresponds to the abstract data type.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 35
35:       def klass
36:         case type
37:           when :integer       then Fixnum
38:           when :float         then Float
39:           when :datetime      then Time
40:           when :date          then Date
41:           when :timestamp     then Time
42:           when :time          then Time
43:           when :text, :string then String
44:           when :binary        then String
45:           when :boolean       then Object
46:         end
47:       end
number?()
    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 30
30:       def number?
31:         @number
32:       end
text?()
    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 26
26:       def text?
27:         @text
28:       end
type_cast(value)

Casts value (which is a String) to an appropriate instance.

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 50
50:       def type_cast(value)
51:         return nil if value.nil?
52:         case type
53:           when :string    then value
54:           when :text      then value
55:           when :integer   then value.to_i rescue value ? 1 : 0
56:           when :float     then value.to_f
57:           when :datetime  then self.class.string_to_time(value)
58:           when :timestamp then self.class.string_to_time(value)
59:           when :time      then self.class.string_to_dummy_time(value)
60:           when :date      then self.class.string_to_date(value)
61:           when :binary    then self.class.binary_to_string(value)
62:           when :boolean   then self.class.value_to_boolean(value)
63:           else value
64:         end
65:       end
type_cast_code(var_name)
    # File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 67
67:       def type_cast_code(var_name)
68:         case type
69:           when :string    then nil
70:           when :text      then nil
71:           when :integer   then "(#{var_name}.to_i rescue #{var_name} ? 1 : 0)"
72:           when :float     then "#{var_name}.to_f"
73:           when :datetime  then "#{self.class.name}.string_to_time(#{var_name})"
74:           when :timestamp then "#{self.class.name}.string_to_time(#{var_name})"
75:           when :time      then "#{self.class.name}.string_to_dummy_time(#{var_name})"
76:           when :date      then "#{self.class.name}.string_to_date(#{var_name})"
77:           when :binary    then "#{self.class.name}.binary_to_string(#{var_name})"
78:           when :boolean   then "#{self.class.name}.value_to_boolean(#{var_name})"
79:           else nil
80:         end
81:       end