Module: EnumTable::SchemaStatements

Defined in:
lib/enum_table/schema_statements.rb

Defined Under Namespace

Classes: NewTable, Table

Constant Summary collapse

DEFAULT_VALUE_ATTRIBUTES =
{type: :string, limit: 255, null: false}.freeze

Instance Method Summary collapse

Instance Method Details

#change_enum_table(table_name) {|Table.new(self, table_name)| ... } ⇒ Object

Yields:

  • (Table.new(self, table_name))


10
11
12
# File 'lib/enum_table/schema_statements.rb', line 10

def change_enum_table(table_name)
  yield Table.new(self, table_name)
end

#create_enum_table(table_name, options = {}) {|table| ... } ⇒ Object

Yields:

  • (table)


3
4
5
6
7
8
# File 'lib/enum_table/schema_statements.rb', line 3

def create_enum_table(table_name, options={})
  table = NewTable.new(self, table_name, options)
  yield table if block_given?
  table._create
  enum_tables_updated
end

#drop_enum_table(table_name) ⇒ Object



14
15
16
17
18
# File 'lib/enum_table/schema_statements.rb', line 14

def drop_enum_table(table_name)
  drop_table table_name
  execute "DELETE FROM enum_tables WHERE table_name = #{quote table_name}"
  enum_tables_updated
end

#enum_tablesObject



20
21
22
23
24
# File 'lib/enum_table/schema_statements.rb', line 20

def enum_tables
  return [] if !table_exists?('enum_tables')
  @enum_tables ||= execute("SELECT table_name FROM enum_tables").
    map { |row| row[0] }.sort
end

#enum_tables_updatedObject



26
27
28
# File 'lib/enum_table/schema_statements.rb', line 26

def enum_tables_updated
  @enum_tables = nil
end