Class: Trestle::Reloader

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

Instance Method Summary collapse

Instance Method Details

#clearObject



32
33
34
# File 'lib/trestle/reloader.rb', line 32

def clear
  Trestle.admins = {}
end

#execute_if_updatedObject



5
6
7
8
9
10
11
# File 'lib/trestle/reloader.rb', line 5

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

#load_pathsObject



36
37
38
# File 'lib/trestle/reloader.rb', line 36

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

#updaterObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/trestle/reloader.rb', line 13

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