Class: Rails::Application::RoutesReloader
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Class Chain:
|
|
|
Instance Chain:
|
|
| Inherits: | Object |
| Defined in: | railties/lib/rails/application/routes_reloader.rb |
Constant Summary
::ActiveSupport::Callbacks - Included
::ActiveSupport::Callbacks - Attributes & Methods
- .__callbacks rw
- #__callbacks readonly
Class Method Summary
Instance Attribute Summary
- #eager_load rw
- #execute_if_updated readonly
- #external_routes readonly
- #paths readonly
- #route_sets readonly
- #run_once_after_load_paths=(value) writeonly Internal use only
Instance Method Summary
- #execute
- #execute_unless_loaded
- #reload!
- #updated? ⇒ Boolean
- #clear! private
- #finalize! private
- #load_paths private
- #revert private
- #run_after_load_paths_callback private
- #updater private
::ActiveSupport::Callbacks - Included
| #run_callbacks | Runs the callbacks for the given event. |
| #halted_callback_hook | A hook invoked every time a before callback is halted. |
Constructor Details
.new(file_watcher: ActiveSupport::FileUpdateChecker) ⇒ RoutesReloader
# 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
Class Attribute Details
.__callbacks (rw)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 70
class_attribute :__callbacks, instance_writer: false, instance_predicate: false, default: {}
Instance Attribute Details
#__callbacks (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 70
class_attribute :__callbacks, instance_writer: false, instance_predicate: false, default: {}
#eager_load (rw)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 11
attr_accessor :eager_load
#execute_if_updated (readonly)
[ GitHub ]#external_routes (readonly)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 10
attr_reader :route_sets, :paths, :external_routes
#paths (readonly)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 10
attr_reader :route_sets, :paths, :external_routes
#route_sets (readonly)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 10
attr_reader :route_sets, :paths, :external_routes
#run_once_after_load_paths=(value) (writeonly)
This method is for internal use only.
[ GitHub ]
# File 'railties/lib/rails/application/routes_reloader.rb', line 12
attr_writer :run_once_after_load_paths # :nodoc:
Instance Method Details
#clear! (private)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 84
def clear! route_sets.each do |routes| routes.disable_clear_and_finalize = true routes.clear! end end
#execute
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 38
def execute updater.execute end
#execute_unless_loaded
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 42
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
#finalize! (private)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 103
def finalize! route_sets.each(&:finalize!) end
#load_paths (private)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 91
def load_paths paths.each { |path| load(path) } run_after_load_paths_callback end
#reload!
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 25
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
#revert (private)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 107
def revert route_sets.each do |routes| routes.disable_clear_and_finalize = false end end
#run_after_load_paths_callback (private)
[ GitHub ]# File 'railties/lib/rails/application/routes_reloader.rb', line 96
def run_after_load_paths_callback if @run_once_after_load_paths @run_once_after_load_paths.call @run_once_after_load_paths = nil end end
#updated? ⇒ Boolean
# File 'railties/lib/rails/application/routes_reloader.rb', line 13
delegate :execute_if_updated, :updated?, to: :updater