Class: DbSchema::DSL

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

Defined Under Namespace

Classes: TableYielder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ DSL

Returns a new instance of DSL.



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

def initialize(block)
  @block  = block
  @schema = []
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/db_schema/dsl.rb', line 3

def block
  @block
end

Instance Method Details

#enum(name, values) ⇒ Object



28
29
30
# File 'lib/db_schema/dsl.rb', line 28

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

#extension(name) ⇒ Object



32
33
34
# File 'lib/db_schema/dsl.rb', line 32

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

#schemaObject



10
11
12
13
14
# File 'lib/db_schema/dsl.rb', line 10

def schema
  block.call(self)

  @schema
end

#table(name, &block) ⇒ Object



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

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

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