Class: MissionControl::Web::Install::MiddlewareGenerator

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

Constant Summary collapse

INITIALIZER_FILE_PATH =
"config/initializers/mission_control_web.rb"

Instance Method Summary collapse

Instance Method Details

#create_initializer_fileObject



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

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

#insert_middleware_configurationObject



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

def insert_middleware_configuration
  initializer = <<~RUBY
    # Middleware
    config.mission_control.web.host_application_name = "My App"
    config.mission_control.web.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

#toggle_middleware_enabledObject



22
23
24
# File 'lib/generators/mission_control/web/install/middleware_generator.rb', line 22

def toggle_middleware_enabled
  gsub_file INITIALIZER_FILE_PATH, "middleware_enabled = false", "middleware_enabled = true"
end