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 51 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 58 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 64 def build_type(type_class) schema = { :name => @name, :quote_column_name => quoted_name }.merge(@opts) [ :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 schema[:length] ||= schema.delete(:size) if schema.key?(:size) if type_class.kind_of?(String) schema[:primitive] = type_class else primitive = type_class.respond_to?(:primitive) ? type_class.primitive : type_class options = @adapter.class.type_map[primitive].dup if type_class.respond_to?(:options) && type_class.options.kind_of?(options.class) options.update(type_class.options) end schema = options.update(schema) end @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 97 def quoted_name @adapter.send(:quote_name, name) end