Skip to Content Skip to Search
Methods
E
L
N
R
Included Modules

Attributes

[RW] eager_load
[R] external_routes
[R] paths
[R] route_sets

Class Public methods

new(file_watcher: ActiveSupport::FileUpdateChecker)

# File railties/lib/rails/application/routes_reloader.rb, line 15
def initialize(file_watcher: ActiveSupport::FileUpdateChecker)
  @paths      = []
  @route_sets = []
  @external_routes = []
  @eager_load = false
  @load_state = nil # nil (not loaded yet) | :loading | :loaded
  @load_lock = Monitor.new
  @file_watcher = file_watcher
end

Instance Public methods

execute()

# File railties/lib/rails/application/routes_reloader.rb, line 43
def execute
  @load_lock.synchronize do
    updater.execute
    @load_state ||= :loaded
  end
end

execute_unless_loaded()

# File railties/lib/rails/application/routes_reloader.rb, line 50
def execute_unless_loaded
  return false if @load_state == :loaded

  @load_lock.synchronize do
    # Another thread finished the load while this one was blocked on
    # @load_lock. Return true so callers like
    # LazyRouteSet#method_missing retry the url helper that was
    # missing when they were called.
    return true if @load_state == :loaded

    # Drawing the routes re-enters this method on the same thread —
    # config/routes.rb itself calls routes.draw — through the
    # reentrant Monitor; without this check the nested call would
    # recurse into another draw.
    return false if @load_state == :loading

    # Hold :loading across after_routes_loaded as well. reload! restores
    # the previous state when it finishes, so if we left that as nil a
    # hook that touched routes would re-enter and draw again.
    @load_state = :loading
    begin
      execute
      ActiveSupport.run_load_hooks(:after_routes_loaded, Rails.application)
      @load_state = :loaded
      true
    ensure
      @load_state = nil if @load_state == :loading
    end
  end
end

loaded()

Returns true if the routes are loaded.

# File railties/lib/rails/application/routes_reloader.rb, line 26
def loaded
  @load_state == :loaded
end

reload!()

# File railties/lib/rails/application/routes_reloader.rb, line 30
def reload!
  @load_lock.synchronize do
    previous_state, @load_state = @load_state, :loading
    clear!
    load_paths
    finalize!
    route_sets.each(&:eager_load!) if eager_load
  ensure
    @load_state = previous_state
    revert
  end
end