auto_reloader 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +6 -3
- data/lib/auto_reloader/version.rb +1 -1
- data/lib/auto_reloader.rb +28 -7
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33298f89941dec545560d13bc5d6da4167d88f28eac35f521a08f04c364e1e4c
|
4
|
+
data.tar.gz: d91db611ba4b31a9067a67a5d88651088a692e3aedb93d6ef8c82572ebbfafa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c96f105df7d697b60a0b459a15e58fe76fb9951e6d9a83b43b5ad33ae2582c611334b3df09fac87698edcc35f9ca3fbd2af888061ebab1cca351d23d35f8636
|
7
|
+
data.tar.gz: 1c5610d6bfd6dc28a1c191c7dffa7b63894570dcdbb95b7a6cf4842e34b964581f665f98d116a1688a046ea00e9aee5e75c2a2cb408cca330b58e68e0d863aad
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ Here's how it would be used in a Rack application.
|
|
32
32
|
app.rb:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
App = ->{['200', {'Content-Type' => 'text/plain'}, ['Sample output']]}
|
35
|
+
App = ->(env){['200', {'Content-Type' => 'text/plain'}, ['Sample output']]}
|
36
36
|
```
|
37
37
|
|
38
38
|
config.ru:
|
@@ -47,7 +47,10 @@ else
|
|
47
47
|
# in the reload! call below
|
48
48
|
AutoReloader.activate reloadable_paths: [__dir__], delay: 1
|
49
49
|
run ->(env) {
|
50
|
-
AutoReloader.reload! do
|
50
|
+
AutoReloader.reload! do |unloaded|
|
51
|
+
# by default, AutoReloader only unloads constants when a watched file changes;
|
52
|
+
# when it unloads code before calling this block, the value for unloaded will be true.
|
53
|
+
ActiveSupport::Dependencies.clear if unloaded && defined?(ActiveSupport::Dependencies)
|
51
54
|
require_relative 'app'
|
52
55
|
App.call env
|
53
56
|
end
|
@@ -74,7 +77,7 @@ changes, it should be quite simple with the `listen` gem. Here's an example:
|
|
74
77
|
app_config = File.expand_path('config/app.json', __dir__)
|
75
78
|
Listen.to(File.expand_path('config', __dir__)) do |added, modified, removed|
|
76
79
|
AutoReloader.force_next_reload if (added + modified + removed).include?(app_config)
|
77
|
-
end
|
80
|
+
end.start
|
78
81
|
```
|
79
82
|
|
80
83
|
## Thread-safety
|
data/lib/auto_reloader.rb
CHANGED
@@ -20,7 +20,7 @@ class AutoReloader
|
|
20
20
|
attr_reader :reloadable_paths, :default_onchange, :default_delay, :default_await_before_unload
|
21
21
|
|
22
22
|
def_delegators :instance, :activate, :reload!, :reloadable_paths, :reloadable_paths=,
|
23
|
-
:unload!, :force_next_reload, :sync_require!, :async_require
|
23
|
+
:unload!, :force_next_reload, :sync_require!, :async_require!, :register_unload_hook
|
24
24
|
|
25
25
|
module RequireOverride
|
26
26
|
def require(path)
|
@@ -54,6 +54,7 @@ class AutoReloader
|
|
54
54
|
@top_level_consts_stack = []
|
55
55
|
@unload_constants = Set.new
|
56
56
|
@unload_files = Set.new
|
57
|
+
@unload_hooks = []
|
57
58
|
@last_reloaded = clock_time
|
58
59
|
try_listen unless watch_paths == false
|
59
60
|
self.reloadable_paths = reloadable_paths
|
@@ -143,7 +144,7 @@ class AutoReloader
|
|
143
144
|
if block_given?
|
144
145
|
@reload_lock.synchronize{ @requests_count += 1 }
|
145
146
|
begin
|
146
|
-
result = yield
|
147
|
+
result = yield !reload_ignored
|
147
148
|
ensure
|
148
149
|
@reload_lock.synchronize{
|
149
150
|
@requests_count -= 1
|
@@ -159,15 +160,33 @@ class AutoReloader
|
|
159
160
|
def unload!
|
160
161
|
@force_reload = false
|
161
162
|
@reload_lock.synchronize do
|
163
|
+
@unload_hooks.reverse_each{|h| run_unload_hook h }
|
162
164
|
@unload_files.each{|f| $LOADED_FEATURES.delete f }
|
163
165
|
@unload_constants.each{|c| safe_remove_constant c }
|
166
|
+
@unload_hooks = []
|
164
167
|
@unload_files = Set.new
|
165
168
|
@unload_constants = Set.new
|
166
169
|
end
|
167
170
|
end
|
168
171
|
|
172
|
+
def register_unload_hook(&hook)
|
173
|
+
raise InvalidUsage, "A block is required for register_unload_hook" unless block_given?
|
174
|
+
@reload_lock.synchronize do
|
175
|
+
@unload_hooks << hook
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def run_unload_hook(hook)
|
180
|
+
hook.call
|
181
|
+
rescue => e
|
182
|
+
puts "Failed to run unload hook in AutoReloader: #{e.message}.\n\n#{e.backtrace.join("\n")}"
|
183
|
+
end
|
184
|
+
|
169
185
|
def stop_listener
|
170
|
-
@
|
186
|
+
@reload_lock.synchronize do
|
187
|
+
@listener.stop if @listener
|
188
|
+
@listener = nil
|
189
|
+
end
|
171
190
|
end
|
172
191
|
|
173
192
|
def force_next_reload
|
@@ -184,11 +203,13 @@ class AutoReloader
|
|
184
203
|
end
|
185
204
|
|
186
205
|
def setup_listener
|
187
|
-
@
|
188
|
-
|
189
|
-
@
|
206
|
+
@reload_lock.synchronize do
|
207
|
+
@listener.stop if @listener
|
208
|
+
@listener = Listen.to(*@reloadable_paths, latency: @watch_latency) do |m, a, r|
|
209
|
+
@paths_changed = [m, a, r].any?{|o| o.any? {|f| reloadable?(f, nil) }}
|
210
|
+
end
|
211
|
+
@listener.start
|
190
212
|
end
|
191
|
-
@listener.start
|
192
213
|
end
|
193
214
|
|
194
215
|
if defined?(Process::CLOCK_MONOTONIC)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_reloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Rosenfeld Rosas
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
-
description:
|
69
|
+
description:
|
70
70
|
email:
|
71
71
|
- rr.rosas@gmail.com
|
72
72
|
executables: []
|
@@ -89,7 +89,7 @@ homepage: https://github.com/rosenfeld/auto_reloader
|
|
89
89
|
licenses:
|
90
90
|
- MIT
|
91
91
|
metadata: {}
|
92
|
-
post_install_message:
|
92
|
+
post_install_message:
|
93
93
|
rdoc_options: []
|
94
94
|
require_paths:
|
95
95
|
- lib
|
@@ -104,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
|
108
|
-
|
109
|
-
signing_key:
|
107
|
+
rubygems_version: 3.3.7
|
108
|
+
signing_key:
|
110
109
|
specification_version: 4
|
111
110
|
summary: A transparent code reloader.
|
112
111
|
test_files: []
|