Class: ActiveRecord::ConnectionAdapters::MysqlColumn

Inherits:
Column
  • Object
show all
Defined in:
lib/connection_adapters/mysql_adapter.rb

Overview

:nodoc:

Constant Summary collapse

@@auto_increment =
"auto_increment"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type = nil, null = true, extra = nil) ⇒ MysqlColumn

Returns a new instance of MysqlColumn.



13
14
15
16
# File 'lib/connection_adapters/mysql_adapter.rb', line 13

def initialize(name, default, sql_type = nil, null = true, extra = nil)
  base_initialize(name, default, sql_type, null)
  @extra = extra
end

Instance Attribute Details

#extraObject (readonly)

Returns the value of attribute extra.



6
7
8
# File 'lib/connection_adapters/mysql_adapter.rb', line 6

def extra
  @extra
end

Instance Method Details

#base_initializeObject

Capture the value of the “EXTRA” column in the column metadata table. This can be used to generate validations



12
# File 'lib/connection_adapters/mysql_adapter.rb', line 12

alias :base_initialize :initialize

#default_specified?Boolean

Until MySQL properly handles default values, I assume that a default value of NULL or empty string means that a default value has not been specified for the column.

We really only care about this when the column is NOT NULL, in which case it should be safe to assume that no one would define the column as NOT NULL and then explicitly set the empty string as the default value. …Right?

Returns:

  • (Boolean)


28
29
30
# File 'lib/connection_adapters/mysql_adapter.rb', line 28

def default_specified?
  !(default.nil? || default.blank?)
end

#generated?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/connection_adapters/mysql_adapter.rb', line 18

def generated?
  @extra == @@auto_increment
end