Class: EnumTable::SchemaStatements::NewTable

Inherits:
Object
  • Object
show all
Defined in:
lib/enum_table/schema_statements.rb

Instance Method Summary collapse

Constructor Details

#initialize(connection, name, options) ⇒ NewTable

Returns a new instance of NewTable.



33
34
35
36
37
38
39
40
41
# File 'lib/enum_table/schema_statements.rb', line 33

def initialize(connection, name, options)
  @connection = connection
  @name = name
  @options = options
  @value = DEFAULT_VALUE_ATTRIBUTES.dup
  @adds = []
  values = options.delete(:values) and
    values.each { |args| add(*args) }
end

Instance Method Details

#_createObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/enum_table/schema_statements.rb', line 43

def _create
  @connection.create_table @name, @options do |t|
    t.column :value, @value.delete(:type), @value
  end
  unless @connection.table_exists?(:enum_tables)
    @connection.create_table :enum_tables, id: false, force: true do |t|
      t.string :table_name, null: false, limit: 255
    end
  end
  @connection.execute "INSERT INTO enum_tables(table_name) VALUES(#{@connection.quote @name})"
  table = Table.new(@connection, @name, 0)
  @adds.each { |args| table.add(*args) }
end

#add(*args) ⇒ Object



61
62
63
# File 'lib/enum_table/schema_statements.rb', line 61

def add(*args)
  @adds << args
end

#value(options) ⇒ Object



57
58
59
# File 'lib/enum_table/schema_statements.rb', line 57

def value(options)
  @value.update(options)
end