Class: ActiveRecord::ConnectionAdapters::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/abstract_adapter.rb

Overview

:nodoc:

Direct Known Subclasses

ColumnWithIdentity, SQLiteColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil) ⇒ Column

The name should contain the name of the column, such as “name” in “name varchar(250)” The default should contain the type-casted default of the column, such as 1 in “count int(11) DEFAULT 1” The type parameter should either contain :integer, :float, :datetime, :date, :text, or :string The sql_type is just used for extracting the limit, such as 10 in “varchar(10)”



166
167
168
169
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 166

def initialize(name, default, sql_type = nil)
  @name, @default, @type = name, default, simplified_type(sql_type)
  @limit = extract_limit(sql_type) unless sql_type.nil?
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



161
162
163
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 161

def default
  @default
end

#limitObject (readonly)

Returns the value of attribute limit.



161
162
163
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 161

def limit
  @limit
end

#nameObject (readonly)

Returns the value of attribute name.



161
162
163
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 161

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



161
162
163
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 161

def type
  @type
end

Instance Method Details

#binary_to_string(value) ⇒ Object



214
215
216
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 214

def binary_to_string(value)
  value
end

#human_nameObject



206
207
208
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 206

def human_name
  Base.human_attribute_name(@name)
end

#klassObject



175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 175

def klass
  case type
    when :integer       then Fixnum
    when :float         then Float
    when :datetime      then Time
    when :date          then Date
    when :timestamp     then Time
    when :time          then Time
    when :text, :string then String
    when :binary        then String
    when :boolean       then Object
  end
end

#string_to_binary(value) ⇒ Object



210
211
212
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 210

def string_to_binary(value)
  value
end

#type_cast(value) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 189

def type_cast(value)
  if value.nil? then return nil end
  case type
    when :string    then value
    when :text      then value
    when :integer   then value.to_i
    when :float     then value.to_f
    when :datetime  then string_to_time(value)
    when :timestamp then string_to_time(value)
    when :time      then string_to_dummy_time(value)
    when :date      then string_to_date(value)
    when :binary    then binary_to_string(value)
    when :boolean   then (value == "t" or value == true ? true : false)
    else value
  end
end