Sha256: 94db474b24d9179bc275075f800e8e07ff26223afb1d6a67b4e29cc6515c3981

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module Trestle
  class Reloader
    delegate :execute, :updated?, to: :updater

    def execute_if_updated
      if defined?(@updater)
        updater.execute_if_updated
      else
        updater.execute
      end
    end

    def updater
      @updater ||= ActiveSupport::FileUpdateChecker.new([], compile_load_paths) do
        begin
          clear

          load_paths.each do |load_path|
            matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
            Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
              require_dependency file.sub(matcher, '\1')
            end
          end
        ensure
          # Ensure that routes are reloaded even if an exception occurs
          # when reading an admin definition file.
          Rails.application.reload_routes!
        end
      end
    end

    def clear
      Trestle.admins = {}
    end

    def load_paths
      ActiveSupport::Dependencies.autoload_paths.grep(/\/app\/admin\Z/)
    end

  private
    def compile_load_paths
      Hash[*load_paths.map { |path| [path, "rb"] }.flatten]
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
trestle-0.8.5 lib/trestle/reloader.rb
trestle-0.8.4 lib/trestle/reloader.rb
trestle-0.8.3 lib/trestle/reloader.rb
trestle-0.8.2 lib/trestle/reloader.rb
trestle-0.8.0 lib/trestle/reloader.rb