Class: ActiveRecord::ConnectionAdapters::ColumnDefinition

Inherits:
Struct
  • Object
show all
Defined in:
lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb

Overview

Abstract representation of a column definition. Instances of this type are typically created by methods in TableDefinition, and added to the columns attribute of said TableDefinition object, in order to be used for generating a number of table creation or table changing SQL statements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#baseObject

Returns the value of attribute base

Returns:

  • (Object)

    the current value of base



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def base
  @base
end

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def default
  @default
end

#limitObject

Returns the value of attribute limit

Returns:

  • (Object)

    the current value of limit



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def limit
  @limit
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def name
  @name
end

#nullObject

Returns the value of attribute null

Returns:

  • (Object)

    the current value of null



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def null
  @null
end

#precisionObject

Returns the value of attribute precision

Returns:

  • (Object)

    the current value of precision



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def precision
  @precision
end

#scaleObject

Returns the value of attribute scale

Returns:

  • (Object)

    the current value of scale



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def scale
  @scale
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



263
264
265
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 263

def type
  @type
end

Instance Method Details

#sql_typeObject



265
266
267
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 265

def sql_type
  base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
end

#to_sqlObject Also known as: to_s



269
270
271
272
273
274
275
276
# File 'lib/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/schema_definitions.rb', line 269

def to_sql
  column_sql = "#{base.quote_column_name(name)} #{sql_type}"
  column_options = {}
  column_options[:null] = null unless null.nil?
  column_options[:default] = default unless default.nil?
  add_column_options!(column_sql, column_options) unless type.to_sym == :primary_key
  column_sql
end