Sha256: b858393c4ea1a3fcd9957cb0de31831d3410ab7aa36dbf4532ae44f963f913ef

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

if Gem::Version.new(Rails.version) < Gem::Version.new(6)
  fail "Rage is only compatible with Rails 6+. Detected Rails version: #{Rails.version}."
end

# load the framework
require "rage/all"

# patch Rack
Iodine.patch_rack

# configure the framework
Rage.config.internal.rails_mode = true

# plug into Rails' Zeitwerk instance to reload the code
Rails.autoloaders.main.on_setup do
  if Iodine.running?
    Rage.code_loader.rails_mode_reload
  end
end

# patch `ActionDispatch::Reloader` to synchronize `reload!` calls
Rails.configuration.after_initialize do
  conditional_mutex = Module.new do
    def call(env)
      @mutex ||= Mutex.new
      if Rails.application.reloader.check!
        @mutex.synchronize { super }
      else
        super
      end
    end
  end

  ActionDispatch::Reloader.prepend(conditional_mutex)

  # use `ActionDispatch::Reloader` in development
  if Rage.env.development?
    Rage.config.middleware.use ActionDispatch::Reloader
  end
end

# clone Rails logger
Rails.configuration.after_initialize do
  if Rails.logger && !Rage.logger
    rails_logdev = Rails.logger.instance_variable_get(:@logdev)
    Rage.configure do
      config.logger = Rage::Logger.new(rails_logdev.dev) if rails_logdev.is_a?(Logger::LogDevice)
    end
  end
end

require "rage/ext/setup"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rage-rb-1.4.0 lib/rage/rails.rb
rage-rb-1.3.0 lib/rage/rails.rb