Module: Racecar::RailsConfigFileLoader

Defined in:
lib/racecar/rails_config_file_loader.rb

Class Method Summary collapse

Class Method Details

.load!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/racecar/rails_config_file_loader.rb', line 5

def self.load!
  config_file = "config/racecar.yml"

  begin
    require "rails"
  rescue LoadError
    # Not a Rails application.
  end

  if defined?(Rails)
    $stderr.puts "=> Detected Rails, booting application..."

    require "./config/environment"

    if (Rails.root + config_file).readable?
      Racecar.config.load_file(config_file, Rails.env)
    end

    # In development, write Rails logs to STDOUT. This mirrors what e.g.
    # Unicorn does.
    if Rails.env.development? && defined?(ActiveSupport::Logger)
      console = ActiveSupport::Logger.new($stdout)
      console.formatter = Rails.logger.formatter
      console.level = Rails.logger.level
      if ::Rails::VERSION::STRING < "7.1"
        Rails.logger.extend(ActiveSupport::Logger.broadcast(console))
      else
        Rails.logger = ActiveSupport::BroadcastLogger.new(Rails.logger, console)
      end
    end
  end
end