Class: DbSchema::DSL
- Inherits:
-
Object
- Object
- DbSchema::DSL
- Defined in:
- lib/db_schema/dsl.rb,
lib/db_schema/dsl/migration.rb
Defined Under Namespace
Classes: Migration, TableYielder
Instance Attribute Summary collapse
-
#migrations ⇒ Object
readonly
Returns the value of attribute migrations.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #enum(name, values) ⇒ Object
- #extension(name) ⇒ Object
-
#initialize(block) ⇒ DSL
constructor
A new instance of DSL.
- #migrate(name, &block) ⇒ Object
- #table(name, &block) ⇒ Object
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
#migrations ⇒ Object (readonly)
Returns the value of attribute migrations.
5 6 7 |
# File 'lib/db_schema/dsl.rb', line 5 def migrations @migrations end |
#schema ⇒ Object (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 |