Class: DbSchema::DSL

Inherits:
Object
  • Object
show all
Defined in:
lib/db_schema/dsl.rb,
lib/db_schema/dsl/migration.rb

Defined Under Namespace

Classes: Migration, TableYielder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ DSL

Returns a new instance of DSL.



7
8
9
10
11
12
# File 'lib/db_schema/dsl.rb', line 7

def initialize(block)
  @schema     = Definitions::Schema.new
  @migrations = []

  block.call(self)
end

Instance Attribute Details

#migrationsObject (readonly)

Returns the value of attribute migrations.



5
6
7
# File 'lib/db_schema/dsl.rb', line 5

def migrations
  @migrations
end

#schemaObject (readonly)

Returns the value of attribute schema.



5
6
7
# File 'lib/db_schema/dsl.rb', line 5

def schema
  @schema
end

Instance Method Details

#enum(name, values) ⇒ Object



26
27
28
# File 'lib/db_schema/dsl.rb', line 26

def enum(name, values)
  @schema.enums << Definitions::Enum.new(name.to_sym, values.map(&:to_sym))
end

#extension(name) ⇒ Object



30
31
32
# File 'lib/db_schema/dsl.rb', line 30

def extension(name)
  @schema.extensions << Definitions::Extension.new(name.to_sym)
end

#migrate(name, &block) ⇒ Object



34
35
36
# File 'lib/db_schema/dsl.rb', line 34

def migrate(name, &block)
  migrations << Migration.new(name, block).migration
end

#table(name, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/db_schema/dsl.rb', line 14

def table(name, &block)
  table_yielder = TableYielder.new(name, block)

  @schema.tables << Definitions::Table.new(
    name,
    fields:       prepare_fields(table_yielder),
    indexes:      table_yielder.indexes,
    checks:       table_yielder.checks,
    foreign_keys: table_yielder.foreign_keys
  )
end