Class: Arfy::MigrationBuilder::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/arfy/migration_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, work_dir, id_generator) ⇒ Builder

Returns a new instance of Builder.



16
17
18
19
20
21
# File 'lib/arfy/migration_builder.rb', line 16

def initialize(name, work_dir, id_generator)
  @id_generator = id_generator
  @work_dir = work_dir
  @name = augment_string(name)
  @builder = nil
end

Instance Method Details

#build(builder = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arfy/migration_builder.rb', line 23

def build(builder = nil)
  @builder = builder
  create_file
  tpl_handler = TemplateHandler.new(migration_template, template_vars)
  tpl_code = tpl_handler.render

  File.open(final_file_path, "w") do |f|
    f << tpl_code
  end

  tpl_code
end

#create_table(table_name) ⇒ Object



36
37
38
# File 'lib/arfy/migration_builder.rb', line 36

def create_table(table_name)
  CreateTable.new(table_name)
end

#drop_table(table_name) ⇒ Object



40
41
42
# File 'lib/arfy/migration_builder.rb', line 40

def drop_table(table_name)
  DropTable.new(table_name)
end