Class: Rack::Unreloader::AutoloadReloader
- Inherits:
-
Reloader
- Object
- Reloader
- Rack::Unreloader::AutoloadReloader
show all
- Defined in:
- lib/rack/unreloader/autoload_reloader.rb
Constant Summary
Constants inherited
from Reloader
Reloader::File
Instance Method Summary
collapse
Methods inherited from Reloader
#clear!, #record_dependency, #require_dependencies, #skip_reload
Constructor Details
Returns a new instance of AutoloadReloader.
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/rack/unreloader/autoload_reloader.rb', line 6
def initialize(opts={})
super
@autoload_files = {}
@autoload_dirs = {}
end
|
Instance Method Details
#autoload_dependencies(paths, opts = {}, &block) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/rack/unreloader/autoload_reloader.rb', line 20
def autoload_dependencies(paths, opts={}, &block)
delete_hook = opts[:delete_hook]
Unreloader.expand_paths(paths).each do |file|
if File.directory?(file)
@autoload_dirs[file] = [nil, [], block, delete_hook]
check_autoload_dir(file)
else
@autoload_files[File.realpath(file)] = [block, modified_at(file), delete_hook]
Unreloader.autoload_constants(yield(file), file, @logger)
end
end
end
|
#check_autoload_dir(dir) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rack/unreloader/autoload_reloader.rb', line 46
def check_autoload_dir(dir)
subdir_times, files, block, delete_hook = md = @autoload_dirs[dir]
return if subdir_times && subdir_times.all?{|subdir, time| File.directory?(subdir) && modified_at(subdir) == time}
md[0] = subdir_times(dir)
cur_files = Unreloader.ruby_files(dir)
return if files == cur_files
removed_files = files - cur_files
new_files = cur_files - files
removed_files.each do |file|
remove_autoload(file, block.call(file)) unless @monitor_files[file]
end
autoload_dependencies(new_files, :delete_hook=>delete_hook, &block) unless new_files.empty?
files.replace(cur_files)
end
|
#reload! ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/rack/unreloader/autoload_reloader.rb', line 70
def reload!
(@autoload_files.keys & $LOADED_FEATURES).each do |file|
log("Autoloaded file required, setting up reloading: #{file}")
block, *metadata = @autoload_files.delete(file)
@constants_defined[file] = block
@monitor_files[file] = metadata
@files[file] = {:features=>Set.new, :constants=>Array(block.call(file))}
end
@autoload_dirs.each_key do |dir|
check_autoload_dir(dir)
end
super
end
|
#remove_autoload(file, strings) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/rack/unreloader/autoload_reloader.rb', line 35
def remove_autoload(file, strings)
strings = Array(strings)
log("Removing autoload for #{file}: #{strings.join(" ")}") unless strings.empty?
strings.each do |s|
obj, mod = Unreloader.split_autoload(s)
obj.send(:remove_const, mod)
end
end
|