Sha256: f4c51bf98478e4ffd0fc26f5bfb9ec151650e5d36d633618158ecb61752f9ed6

Contents?: true

Size: 1 KB

Versions: 16

Compression:

Stored size: 1 KB

Contents

module SOULs
  class DB < Thor
    desc "create_migration [CLASS_NAME]", "Create ActiveRecord Migration File"
    def create_migration(class_name)
      pluralized_class_name = class_name.underscore.pluralize
      singularized_class_name = class_name.underscore.singularize
      SOULs::DB.new.invoke(:model, [singularized_class_name], {})
      SOULs::DB.new.invoke(:rspec_model, [singularized_class_name], {})
      SOULs::Painter.create_file("")
      system("rake db:create_migration NAME=create_#{pluralized_class_name}")
      file_path = Dir["db/migrate/*create_#{pluralized_class_name}.rb"].first
      File.open(file_path, "w") do |f|
        f.write(<<~TEXT)
          class Create#{pluralized_class_name.camelize} < ActiveRecord::Migration[6.1]
            def change
              create_table :#{pluralized_class_name} do |t|

                t.boolean :is_deleted, null: false, default: false
                t.timestamps
              end
            end
          end
        TEXT
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
souls-4.1.2 lib/souls/cli/db/create_migration.rb
souls-4.1.1 lib/souls/cli/db/create_migration.rb
souls-4.1.0 lib/souls/cli/db/create_migration.rb
souls-4.0.3 lib/souls/cli/db/create_migration.rb
souls-4.0.2 lib/souls/cli/db/create_migration.rb
souls-4.0.1 lib/souls/cli/db/create_migration.rb
souls-4.0.0 lib/souls/cli/db/create_migration.rb
souls-3.0.8 lib/souls/cli/db/create_migration.rb
souls-3.0.7 lib/souls/cli/db/create_migration.rb
souls-3.0.6 lib/souls/cli/db/create_migration.rb
souls-3.0.5 lib/souls/cli/db/create_migration.rb
souls-3.0.4 lib/souls/cli/db/create_migration.rb
souls-3.0.3 lib/souls/cli/db/create_migration.rb
souls-3.0.2 lib/souls/cli/db/create_migration.rb
souls-3.0.1 lib/souls/cli/db/create_migration.rb
souls-3.0.0 lib/souls/cli/db/create_migration.rb