Skip to content
This repository
tag: v3.0.0.beta2
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 46 lines (37 sloc) 1.035 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
module Rails
  class Application
    class RoutesReloader
      attr_reader :paths

      def initialize
        @paths, @last_change_at = [], nil
      end

      def changed_at
        routes_changed_at = nil

        paths.each do |path|
          config_changed_at = File.stat(path).mtime

          if routes_changed_at.nil? || config_changed_at > routes_changed_at
            routes_changed_at = config_changed_at
          end
        end

        routes_changed_at
      end

      def reload!
        routes = Rails::Application.routes
        routes.disable_clear_and_finalize = true

        routes.clear!
        paths.each { |path| load(path) }
        ActiveSupport.on_load(:action_controller) { routes.finalize! }

        nil
      ensure
        routes.disable_clear_and_finalize = false
      end

      def reload_if_changed
        current_change_at = changed_at
        if @last_change_at != current_change_at
          @last_change_at = current_change_at
          reload!
        end
      end
    end
  end
end
Something went wrong with that request. Please try again.