Class: MissionControl::Web::Install::AdminGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/mission_control/web/install/admin_generator.rb

Constant Summary collapse

INITIALIZER_FILE_PATH =
"config/initializers/mission_control_web.rb"

Instance Method Summary collapse

Instance Method Details

#add_engine_routesObject



25
26
27
# File 'lib/generators/mission_control/web/install/admin_generator.rb', line 25

def add_engine_routes
  route "mount MissionControl::Web::Engine => '/mission_control-web'"
end

#copy_migrationsObject



29
30
31
# File 'lib/generators/mission_control/web/install/admin_generator.rb', line 29

def copy_migrations
  rake "mission_control_web:install:migrations"
end

#create_initializer_fileObject



5
6
7
8
9
10
# File 'lib/generators/mission_control/web/install/admin_generator.rb', line 5

def create_initializer_file
  create_file INITIALIZER_FILE_PATH, <<~RUBY, skip: true
    Rails.application.configure do
    end
  RUBY
end

#insert_admin_configurationObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/generators/mission_control/web/install/admin_generator.rb', line 12

def insert_admin_configuration
  initializer = <<~RUBY
    config.mission_control.web.middleware_enabled = false

    # Admin
    config.mission_control.web.administered_applications = [
      { name: "My App", redis: Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0")) }
    ]
  RUBY

  insert_into_file INITIALIZER_FILE_PATH, indent(initializer), after: "Rails.application.configure do\n"
end

#run_migrationsObject



33
34
35
36
# File 'lib/generators/mission_control/web/install/admin_generator.rb', line 33

def run_migrations
  say "Running migrations..."
  rails_command "db:migrate"
end