Class: SoftTrash::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- SoftTrash::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/soft_trash/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(dirname) ⇒ Object
10 11 12 13 |
# File 'lib/generators/soft_trash/install_generator.rb', line 10 def self.next_migration_number(dirname) next_migration_number = current_migration_number(dirname) + 1 [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.3d" % next_migration_number].max end |
Instance Method Details
#create_migration_file ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/generators/soft_trash/install_generator.rb', line 16 def create_migration_file migration_template( 'add_deleted_at_to_tables.rb.erb', "db/migrate/add_deleted_at_to_#{table_name}.rb", migration_version: migration_version, table_name: table_name ) end |
#inject_soft_trash_module ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/generators/soft_trash/install_generator.rb', line 25 def inject_soft_trash_module model_path = "app/models/#{model_name.singularize}.rb" if File.exist?(model_path) inject_into_file model_path, after: "ApplicationRecord\n" do " include SoftTrash::Model\n" end else create_file model_path do "class #{model_name.classify} < ApplicationRecord\n" + " include SoftTrash::Model\n" + "end\n" end end end |