Sha256: e47d54b4f3e29a89c74a6f3a4ce58585d2f8346a7d5b2c8a8ca8c1291bb4846f

Contents?: true

Size: 1.06 KB

Versions: 126

Compression:

Stored size: 1.06 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 do |routes|
          routes.finalize!
        end
      end

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

Version data entries

126 entries across 122 versions & 10 rubygems

Version Path
railties-4.2.1.rc3 lib/rails/application/routes_reloader.rb
railties-4.1.10.rc2 lib/rails/application/routes_reloader.rb
railties-4.2.1.rc2 lib/rails/application/routes_reloader.rb
railties-4.1.10.rc1 lib/rails/application/routes_reloader.rb
railties-4.2.1.rc1 lib/rails/application/routes_reloader.rb
activejob-lock-0.0.1 rails/railties/lib/rails/application/routes_reloader.rb
railties-4.0.13 lib/rails/application/routes_reloader.rb
railties-4.1.9 lib/rails/application/routes_reloader.rb
railties-4.1.9.rc1 lib/rails/application/routes_reloader.rb
railties-4.0.13.rc1 lib/rails/application/routes_reloader.rb
railties-4.2.0 lib/rails/application/routes_reloader.rb
railties-4.2.0.rc3 lib/rails/application/routes_reloader.rb
railties-4.2.0.rc2 lib/rails/application/routes_reloader.rb
railties-4.2.0.rc1 lib/rails/application/routes_reloader.rb
railties-4.1.7.1 lib/rails/application/routes_reloader.rb
railties-4.0.11.1 lib/rails/application/routes_reloader.rb
railties-4.1.8 lib/rails/application/routes_reloader.rb
railties-4.0.12 lib/rails/application/routes_reloader.rb
railties-4.2.0.beta4 lib/rails/application/routes_reloader.rb
railties-4.2.0.beta3 lib/rails/application/routes_reloader.rb