123456789_123456789_123456789_123456789_123456789_

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

CALLBACK_FILTER_TYPES

::ActiveSupport::Callbacks - Attributes & Methods

Class Method Summary

::ActiveSupport::DescendantsTracker - self

descendants

See additional method definition at line 104.

subclasses

See additional method definition at line 100.

clear, disable_clear!, reject!,
store_inherited

This is the only method that is not thread safe, but is only ever called during the eager loading phase.

Instance Attribute Summary

Instance Method Summary

::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

.newRoutesReloader

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 15

def initialize
  @paths      = []
  @route_sets = []
  @external_routes = []
  @eager_load = false
end

Class Attribute Details

.__callbacks (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 70

class_attribute :__callbacks, instance_writer: false, default: {}

.__callbacks?Boolean (rw)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 70

class_attribute :__callbacks, instance_writer: false, default: {}

Instance Attribute Details

#__callbacks (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 70

class_attribute :__callbacks, instance_writer: false, default: {}

#__callbacks?Boolean (readonly)

[ GitHub ]

  
# File 'activesupport/lib/active_support/callbacks.rb', line 70

class_attribute :__callbacks, instance_writer: false, default: {}

#eager_load (rw)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 11

attr_accessor :eager_load

#execute (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 13

delegate :execute_if_updated, :execute, :updated?, to: :updater

#execute_if_updated (readonly)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 13

delegate :execute_if_updated, :execute, :updated?, to: :updater

#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_after_load_paths (rw, private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 54

def run_after_load_paths
  @run_after_load_paths ||= -> { }
end

#run_after_load_paths=(value) (rw)

This method is for internal use only.
[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 12

attr_writer :run_after_load_paths # :nodoc:

Instance Method Details

#clear! (private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 42

def clear!
  route_sets.each do |routes|
    routes.disable_clear_and_finalize = true
    routes.clear!
  end
end

#finalize! (private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 58

def finalize!
  route_sets.each(&:finalize!)
end

#load_paths (private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 49

def load_paths
  paths.each { |path| load(path) }
  run_after_load_paths.call
end

#reload!

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 22

def reload!
  clear!
  load_paths
  finalize!
  route_sets.each(&:eager_load!) if eager_load
ensure
  revert
end

#revert (private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 62

def revert
  route_sets.each do |routes|
    routes.disable_clear_and_finalize = false
  end
end

#updated?Boolean

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 13

delegate :execute_if_updated, :execute, :updated?, to: :updater

#updater (private)

[ GitHub ]

  
# File 'railties/lib/rails/application/routes_reloader.rb', line 32

def updater
  @updater ||= begin
    dirs = @external_routes.each_with_object({}) do |dir, hash|
      hash[dir.to_s] = %w(rb)
    end

    ActiveSupport::FileUpdateChecker.new(paths, dirs) { reload! }
  end
end