Class: SQL::TableCreator::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/sql/table_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter, name, type, opts = {}) ⇒ Column

Returns a new instance of Column.



30
31
32
33
34
35
# File 'lib/sql/table_creator.rb', line 30

def initialize(adapter, name, type, opts = {})
  @adapter = adapter
  @name = name.to_s
  @opts = opts
  @type = build_type(type)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



28
29
30
# File 'lib/sql/table_creator.rb', line 28

def name
  @name
end

#typeObject

Returns the value of attribute type.



28
29
30
# File 'lib/sql/table_creator.rb', line 28

def type
  @type
end

Instance Method Details

#build_type(type_class) ⇒ Object



37
38
39
40
41
# File 'lib/sql/table_creator.rb', line 37

def build_type(type_class)
  schema = {:name => @name, :quote_column_name => quoted_name}.merge(@opts)
  schema = @adapter.class.type_map[type_class].merge(schema)
  @adapter.property_schema_statement(schema)
end

#quoted_nameObject



47
48
49
# File 'lib/sql/table_creator.rb', line 47

def quoted_name
  @adapter.send(:quote_column_name, name)
end

#to_sqlObject



43
44
45
# File 'lib/sql/table_creator.rb', line 43

def to_sql
    type
end