class SQL::TableCreator::Column

Attributes

name[RW]
type[RW]

Public Class Methods

new(adapter, name, type, opts = {}) click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 56
def initialize(adapter, name, type, opts = {})
  @adapter = adapter
  @name = name.to_s
  @opts = opts
  @type = build_type(type)
end

Public Instance Methods

to_sql() click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 63
def to_sql
  type
end

Private Instance Methods

build_type(type_class) click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 69
def build_type(type_class)
  schema = { :name => @name, :quote_column_name => quoted_name }

  [ :nullable, :nullable? ].each do |option|
    next if (value = schema.delete(option)).nil?
    warn "#{option.inspect} is deprecated, use :allow_nil instead"
    schema[:allow_nil] = value unless schema.key?(:allow_nil)
  end

  unless schema.key?(:allow_nil)
    schema[:allow_nil] = !schema[:not_null]
  end

  if type_class.kind_of?(String)
    schema[:primitive] = type_class
  else
    type_map  = @adapter.class.type_map
    primitive = type_class.respond_to?(:primitive) ? type_class.primitive : type_class
    options   = (type_map[type_class] || type_map[primitive])

    schema.update(type_class.options) if type_class.respond_to?(:options)
    schema.update(options)

    schema.delete(:length) if type_class == DataMapper::Property::Text
  end

  schema.update(@opts)

  schema[:length] = schema.delete(:size) if schema.key?(:size)

  @adapter.send(:with_connection) do |connection|
    @adapter.property_schema_statement(connection, schema)
  end
end
quoted_name() click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 104
def quoted_name
  @adapter.send(:quote_name, name)
end