auto_reloader 0.4.1 → 0.6.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 +2 -2
- data/auto_reloader.gemspec +2 -2
- data/lib/auto_reloader/version.rb +1 -1
- data/lib/auto_reloader.rb +27 -6
- metadata +15 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad35373d8e017a92e8f3e2e621f8c790dd951c7ea5379dec9c4988ac1840c078
|
4
|
+
data.tar.gz: 324d203076505d3d1e9747ac875e31dfa203907cb6eea8deee08fd7d8b8da77e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d99817d6401af905cb766ff56191702b1069899bf6a47d4c434990ba42d1d42885206f031e5eec0b9f681428690dd73b924809f228c6a769dcdffe3efbaeb74
|
7
|
+
data.tar.gz: 1091bbe85c08614d4a1f96fe607fe02d6a01a4b3d9bd1112661b6d10d56f30eb20b8b98fb59d6c3c4ec805851e42553eaceee417b49633f19416b522d5ff2834
|
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:
|
@@ -77,7 +77,7 @@ changes, it should be quite simple with the `listen` gem. Here's an example:
|
|
77
77
|
app_config = File.expand_path('config/app.json', __dir__)
|
78
78
|
Listen.to(File.expand_path('config', __dir__)) do |added, modified, removed|
|
79
79
|
AutoReloader.force_next_reload if (added + modified + removed).include?(app_config)
|
80
|
-
end
|
80
|
+
end.start
|
81
81
|
```
|
82
82
|
|
83
83
|
## Thread-safety
|
data/auto_reloader.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
17
17
|
spec.require_paths = ['lib']
|
18
18
|
|
19
|
-
spec.add_development_dependency 'bundler', '
|
20
|
-
spec.add_development_dependency 'rake', '
|
19
|
+
spec.add_development_dependency 'bundler', '>= 2.2.33'
|
20
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
21
21
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
22
22
|
spec.add_development_dependency 'listen', '~> 3.0'
|
23
23
|
end
|
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
|
@@ -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,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_reloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.33
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: []
|