Class: EIVO::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- EIVO::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/eivo/install_generator.rb
Class Method Summary collapse
- .namespace(name = nil) ⇒ Object
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
Class Method Details
.namespace(name = nil) ⇒ Object
11 12 13 |
# File 'lib/generators/eivo/install_generator.rb', line 11 def self.namespace(name = nil) @namespace ||= super.sub('e_i_v_o', 'eivo') end |
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
16 17 18 19 |
# File 'lib/generators/eivo/install_generator.rb', line 16 def self.next_migration_number(dirname) next_migration_number = current_migration_number(dirname) + 1 ActiveRecord::Migration.next_migration_number(next_migration_number) end |
Instance Method Details
#create_initializer_file ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/eivo/install_generator.rb', line 21 def create_initializer_file @application = Rails.application.class.module_parent_name remove_dir 'config/environments' copy_file 'Gemfile' copy_file 'Procfile' copy_file '.env.example' copy_file '.ruby-version' copy_file '.rubocop.yml' create_restart_files template 'config/application.rb' copy_file 'config/puma.rb' copy_file 'config/database.example.yml' template 'config/database.local.yml', 'config/database.yml', skip: true copy_file 'app/controllers/application_controller.rb' migration_template 'db/migrate/enable_pgcrypto_extension.rb', 'db/migrate/enable_pgcrypto_extension.rb', skip: true migration_template 'db/migrate/enable_pg_stat_statements_extension.rb', 'db/migrate/enable_pg_stat_statements_extension.rb', skip: true migration_template 'db/migrate/enable_btree_gin_extension.rb', 'db/migrate/enable_btree_gin_extension.rb', skip: true migration_template 'db/migrate/enable_unaccent_extension.rb', 'db/migrate/enable_unaccent_extension.rb', skip: true route "mount EIVO::Engine => '/'" end |
#create_restart_files ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/generators/eivo/install_generator.rb', line 49 def create_restart_files restart_code = " ### EIVO begin ###\n\n bundle exec pumactl -F config/puma.rb restart\n\n ### EIVO end ###\n EIVO_COMMAND\n\n stop_code = <<~'EIVO_COMMAND'\n ### EIVO begin ###\n\n bundle exec pumactl -F config/puma.rb stop\n\n ### EIVO end ###\n EIVO_COMMAND\n\n header_production = <<~'EIVO_COMMAND'\n #!/usr/bin/env bash\n export RACK_ENV=\"production\"\n export RAILS_ENV=\"production\"\n export RAILS_DAEMONIZE=\"true\"\n\n EIVO_COMMAND\n\n header_staging = <<~'EIVO_COMMAND'\n #!/usr/bin/env bash\n export RACK_ENV=\"staging\"\n export RAILS_ENV=\"staging\"\n export RAILS_DAEMONIZE=\"true\"\n\n EIVO_COMMAND\n\n create_file 'restart_production.sh', header_production, skip: true\n create_file 'stop_production.sh', header_production, skip: true\n create_file 'restart_staging.sh', header_staging, skip: true\n create_file 'stop_staging.sh', header_staging, skip: true\n\n # Remove old code if present\n regexp = /\\n### EIVO begin ###.*### EIVO end ###/m\n gsub_file 'restart_production.sh', regexp, ''\n gsub_file 'restart_staging.sh', regexp, ''\n gsub_file 'stop_production.sh', regexp, ''\n gsub_file 'stop_staging.sh', regexp, ''\n\n # Inject new code\n inject_into_file 'restart_production.sh', restart_code, after: header_production\n inject_into_file 'stop_production.sh', stop_code, after: header_production\n inject_into_file 'restart_staging.sh', restart_code, after: header_staging\n inject_into_file 'stop_staging.sh', stop_code, after: header_staging\n\n chmod 'restart_production.sh', 0o755\n chmod 'stop_production.sh', 0o755\n chmod 'restart_staging.sh', 0o755\n chmod 'stop_staging.sh', 0o755\nend\n" |