Class: Modulorails::HealthCheckGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/modulorails/healthcheck/health_check_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_config_fileObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/modulorails/healthcheck/health_check_generator.rb', line 10

def create_config_file
  # Update the template
  template 'config/initializers/health_check.rb'

  # Add the route
  unless File.read(Rails.root.join('config/routes.rb')).match?('health_check_routes')
    inject_into_file 'config/routes.rb', "  health_check_routes\n\n", after: "Rails.application.routes.draw do\n"
  end

  # Update the gem and the Gemfile.lock
  system('bundle install')

  # Create file to avoid this generator on next modulorails launch
  create_keep_file
rescue StandardError => e
  warn("[Modulorails] Error: cannot generate health_check configuration: #{e.message}")
end