Sha256: 27a6343366658c19efaeedb2073f51e387024ac64e48ab6558e450631b76ce3a
Contents?: true
Size: 1.51 KB
Versions: 29
Compression:
Stored size: 1.51 KB
Contents
require 'active_support' require 'active_support/core_ext' require 'string/builder' require 'thor' module Eucalypt module Generators module Drop class Index < Thor::Group include Thor::Actions include Eucalypt::Helpers using String::Builder def self.source_root File.join File.dirname(File.dirname(File.dirname __dir__)) end def generate(table:, columns: [], name:) table = Inflect.resource_keep_inflection(table.to_s) name = Inflect.resource_keep_inflection(name.to_s) sleep 1 migration_name = "drop_#{name}_from_#{table}" 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 << " remove_index :#{table}" unless name.empty? || name == 'index' s << ", name: :#{name}" else unless columns.empty? columns.map!(&:to_sym) s << ", column: " s << (columns.size == 1 ? ":#{columns.first}" : "%i[#{columns*' '}]") end end s << "\n" end end end end end end end
Version data entries
29 entries across 29 versions & 1 rubygems