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)”



169
170
171
172
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 169

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.



164
165
166
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 164

def default
  @default
end

#limitObject (readonly)

Returns the value of attribute limit.



164
165
166
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 164

def limit
  @limit
end

#nameObject (readonly)

Returns the value of attribute name.



164
165
166
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 164

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



164
165
166
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 164

def type
  @type
end

Instance Method Details

#binary_to_string(value) ⇒ Object



217
218
219
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 217

def binary_to_string(value)
  value
end

#human_nameObject



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

def human_name
  Base.human_attribute_name(@name)
end

#klassObject



178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 178

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



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

def string_to_binary(value)
  value
end

#type_cast(value) ⇒ Object



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

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