class Mononoke::InitGenerator

Public Instance Methods

copy_config_file() click to toggle source
# File lib/generators/mononoke/init_generator.rb, line 9
def copy_config_file
  template 'uptime.rb', File.join('config/initializers', 'uptime.rb')
  template 'health_check_controller.rb', File.join('app/controllers', 'health_check_controller.rb')
  append_diagostics_routes unless File.foreach('config/routes.rb').grep(/diagnostics/).present?
end

Private Instance Methods

append_diagostics_routes() click to toggle source
# File lib/generators/mononoke/init_generator.rb, line 17
def append_diagostics_routes
  p 'Add Diagnostics routes in `configs/routes.rb`'
  tempfile = File.open('routes.tmp', 'w')
  f = File.new('config/routes.rb')
  f.each do |line|
    tempfile << line
    tempfile << diagnostics_str if /format: :json/.match?(line.downcase)
  end
  f.close
  tempfile.close
  FileUtils.mv('routes.tmp', 'config/routes.rb')
end
diagnostics_str() click to toggle source
# File lib/generators/mononoke/init_generator.rb, line 30
    def diagnostics_str
      @diagnostics_str ||= <<~FOO
        root to: 'health_check#index'
        scope '/diagnostics' do
          get '/quickhealth', to: 'health_check#quick_health'
          get '/health',      to: 'health_check#health'
          get '/version',     to: 'health_check#version'
          get '/uptime',      to: 'health_check#uptime'
        end
      FOO
    end