Sha256: 4ee377be7d6bbef2465a7c5b6fc9ede820be595ec3012ebc6d5e57637e25fbca

Contents?: true

Size: 1.02 KB

Versions: 35

Compression:

Stored size: 1.02 KB

Contents

require "active_support/core_ext/module/delegation"

module Rails
  class Application
    class RoutesReloader
      attr_reader :route_sets, :paths
      delegate :execute_if_updated, :execute, :updated?, to: :updater

      def initialize
        @paths      = []
        @route_sets = []
      end

      def reload!
        clear!
        load_paths
        finalize!
      ensure
        revert
      end

    private

      def updater
        @updater ||= begin
          updater = ActiveSupport::FileUpdateChecker.new(paths) { reload! }
          updater.execute
          updater
        end
      end

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

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

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

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

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
railties-5.0.7.2 lib/rails/application/routes_reloader.rb
railties-5.0.7.1 lib/rails/application/routes_reloader.rb
railties-5.0.7 lib/rails/application/routes_reloader.rb
railties-5.0.6 lib/rails/application/routes_reloader.rb
railties-5.0.6.rc1 lib/rails/application/routes_reloader.rb
railties-5.0.5 lib/rails/application/routes_reloader.rb
railties-5.0.5.rc2 lib/rails/application/routes_reloader.rb
railties-5.0.5.rc1 lib/rails/application/routes_reloader.rb
railties-5.0.4 lib/rails/application/routes_reloader.rb
railties-5.0.4.rc1 lib/rails/application/routes_reloader.rb
railties-5.0.3 lib/rails/application/routes_reloader.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/railties-5.0.2/lib/rails/application/routes_reloader.rb
railties-5.0.2 lib/rails/application/routes_reloader.rb
railties-5.0.2.rc1 lib/rails/application/routes_reloader.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/application/routes_reloader.rb