Sha256: 00768bf025f78b86d6aa67ae3ca60b13b95102b43c11c79143bb092cfe714a47

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

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

    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
      Trestle.config.load_paths.map { |path| path.respond_to?(:call) ? path.call : path }.flatten.map(&:to_s)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trestle-0.9.3 lib/trestle/reloader.rb