Class: Eucalypt::Generators::Drop::Table

Inherits:
Thor::Group
  • Object
show all
Includes:
Helpers, Thor::Actions
Defined in:
lib/eucalypt/migration/namespaces/migration-drop/generators/table.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



14
15
16
# File 'lib/eucalypt/migration/namespaces/migration-drop/generators/table.rb', line 14

def self.source_root
  File.join File.dirname(File.dirname(File.dirname __dir__))
end

Instance Method Details

#generate(name:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/eucalypt/migration/namespaces/migration-drop/generators/table.rb', line 18

def generate(name:)
  name = Inflect.resource_keep_inflection(name.to_s)

  sleep 1
  migration_name = "drop_#{name}"
  migration = Eucalypt::Helpers::Migration[title: migration_name, template: 'migration_base.tt']
  return unless migration.create_anyway? if migration.exists?
  config = {migration_class_name: migration_name.camelize}
  template migration.template, migration.file_path, config

  insert_into_file migration.file_path, :after => "def change\n" do
    String.build do |s|
      s << "    drop_table :#{name}\n"
    end
  end
end