auto_reloader 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7e177122757b5b4f8c555813ae048ed0f8ed1905
4
- data.tar.gz: fcd9ad0f2847ecd33e109cf2a452655f3405defe
2
+ SHA256:
3
+ metadata.gz: 33298f89941dec545560d13bc5d6da4167d88f28eac35f521a08f04c364e1e4c
4
+ data.tar.gz: d91db611ba4b31a9067a67a5d88651088a692e3aedb93d6ef8c82572ebbfafa7
5
5
  SHA512:
6
- metadata.gz: e117321d8a5a284b018a027477d0ae7fa420049dbf1d0a5687f9d925f194d594bd35e0bc82d188c05a3dd82c846b23cbcde77b9b189acae7a1526aac1c7b407f
7
- data.tar.gz: 13f25050c47b0ec2b8d9ec93aa1062bff51471fcbd27ee3dd5219c9e2a3988124ffec5f8bf76cec73ece2ee4ef1cf475c9d739573af6278258a27266756ee3be
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:
@@ -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
@@ -1,3 +1,3 @@
1
1
  class AutoReloader
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  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
- @listener.stop if @listener
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
- @listener.stop if @listener
188
- @listener = Listen.to(*@reloadable_paths, latency: @watch_latency) do |m, a, r|
189
- @paths_changed = [m, a, r].any?{|o| o.any? {|f| reloadable?(f, nil) }}
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.1
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: 2017-03-08 00:00:00.000000000 Z
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
- rubyforge_project:
108
- rubygems_version: 2.6.8
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: []