Class: SQL::TableCreator::Column
- Defined in:
- lib/mack-data_mapper/dm_patches/migrations.rb,
lib/gems/dm-migrations-0.9.9/lib/sql/table_creator.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#build_type(type_class) ⇒ Object
:nodoc:.
-
#initialize(adapter, name, type, opts = {}) ⇒ Column
constructor
A new instance of Column.
- #quoted_name ⇒ Object
- #to_sql ⇒ Object
Constructor Details
#initialize(adapter, name, type, opts = {}) ⇒ Column
Returns a new instance of Column.
51 52 53 54 55 56 |
# File 'lib/gems/dm-migrations-0.9.9/lib/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 |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
49 50 51 |
# File 'lib/gems/dm-migrations-0.9.9/lib/sql/table_creator.rb', line 49 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
49 50 51 |
# File 'lib/gems/dm-migrations-0.9.9/lib/sql/table_creator.rb', line 49 def type @type end |
Instance Method Details
#build_type(type_class) ⇒ Object
:nodoc:
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mack-data_mapper/dm_patches/migrations.rb', line 48 def build_type(type_class) schema = {:name => @name, :quote_column_name => quoted_name}.merge(@opts) schema[:serial?] = [schema[:serial?], schema[:serial], false].compact.first schema[:nullable?] = [schema[:nullable?], schema[:nullable], (!schema[:not_null] unless schema[:not_null].nil?), true].compact.first if type_class.is_a?(String) schema[:primitive] = type_class else schema = @adapter.class.type_map[type_class].merge(schema) end @adapter.property_schema_statement(schema) end |
#quoted_name ⇒ Object
74 75 76 |
# File 'lib/gems/dm-migrations-0.9.9/lib/sql/table_creator.rb', line 74 def quoted_name @adapter.send(:quote_column_name, name) end |
#to_sql ⇒ Object
70 71 72 |
# File 'lib/gems/dm-migrations-0.9.9/lib/sql/table_creator.rb', line 70 def to_sql type end |