Class: Trestle::Reloader

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/reloader.rb

Instance Method Summary collapse

Instance Method Details

#clearObject


24
25
26
# File 'lib/trestle/reloader.rb', line 24

def clear
  Trestle.admins = {}
end

#load_pathsObject


28
29
30
# File 'lib/trestle/reloader.rb', line 28

def load_paths
  Trestle.config.load_paths.map { |path| path.respond_to?(:call) ? path.call : path }.flatten.map(&:to_s)
end

#updaterObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/trestle/reloader.rb', line 5

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