auto_reloader 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/auto_reloader/version.rb +1 -1
- data/lib/auto_reloader.rb +9 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16551c2344afe661a841af495ae36fc631de4c4c
|
4
|
+
data.tar.gz: cda47b63ff8f825edac189b39d1ef6bbb1edd093
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6b94516fd14447ccdc77e2c26a40e85b4f64ea33353a8c833333612be4c7e88e09d028f658e3bbdd075159c4a4103e330f1197eb5345b941a4ad4ba82385fbf
|
7
|
+
data.tar.gz: 3db77d13f21fffeb66cc90cd887306284d5123f0433f93589242224805fc1e7b37dd8e2f147a9c3ede24d5ffccd639ec1e6261818cc05b554039cb85f002357f
|
data/README.md
CHANGED
@@ -65,6 +65,18 @@ up `reload!` when no changes happened although it won't probably do much differe
|
|
65
65
|
your application has tons of reloadable files loaded upon each request. If you don't want to
|
66
66
|
use `listen` when available, set `watch_paths: false` when calling `activate`.
|
67
67
|
|
68
|
+
Currently AutoReloader does not watch files other than those being required and I'm not sure
|
69
|
+
if it would be a good idea to provide this kind of feature through some option. However if
|
70
|
+
you want to force unloading the reloadable files when some configuration file (YAML, JSON, etc)
|
71
|
+
changes, it should be quite simple with the `listen` gem. Here's an example:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
app_config = File.expand_path('config/app.json', __dir__)
|
75
|
+
Listen.to(File.expand_path('config', __dir__)) do |added, modified, removed|
|
76
|
+
AutoReloader.force_next_reload if (added + modified + removed).include?(app_config)
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
68
80
|
## Known Caveats
|
69
81
|
|
70
82
|
In order to work transparently AutoReloader will override `require` and `require_relative` when
|
data/lib/auto_reloader.rb
CHANGED
@@ -12,7 +12,8 @@ class AutoReloader
|
|
12
12
|
|
13
13
|
attr_reader :reloadable_paths, :default_onchange, :default_delay
|
14
14
|
|
15
|
-
def_delegators :instance, :activate, :reload!, :reloadable_paths, :reloadable_paths=,
|
15
|
+
def_delegators :instance, :activate, :reload!, :reloadable_paths, :reloadable_paths=,
|
16
|
+
:unload!, :force_next_reload
|
16
17
|
|
17
18
|
module RequireOverride
|
18
19
|
def require(path)
|
@@ -104,6 +105,7 @@ class AutoReloader
|
|
104
105
|
end
|
105
106
|
|
106
107
|
def unload!
|
108
|
+
@force_reload = false
|
107
109
|
@reload_lock.synchronize do
|
108
110
|
@unload_files.each{|f| $LOADED_FEATURES.delete f }
|
109
111
|
@unload_constants.each{|c| Object.send :remove_const, c }
|
@@ -116,6 +118,10 @@ class AutoReloader
|
|
116
118
|
@listener.stop if @listener
|
117
119
|
end
|
118
120
|
|
121
|
+
def force_next_reload
|
122
|
+
@force_reload = true
|
123
|
+
end
|
124
|
+
|
119
125
|
private
|
120
126
|
|
121
127
|
def try_listen
|
@@ -128,7 +134,7 @@ class AutoReloader
|
|
128
134
|
def setup_listener
|
129
135
|
@listener.stop if @listener
|
130
136
|
@listener = Listen.to(*@reloadable_paths, latency: @watch_latency) do |m, a, r|
|
131
|
-
@paths_changed =
|
137
|
+
@paths_changed = [m, a, r].any?{|o| o.any? {|f| reloadable?(f, nil) }}
|
132
138
|
end
|
133
139
|
@listener.start
|
134
140
|
end
|
@@ -148,6 +154,7 @@ class AutoReloader
|
|
148
154
|
end
|
149
155
|
|
150
156
|
def ignore_reload?(delay, onchange)
|
157
|
+
return false if @force_reload
|
151
158
|
(delay && (clock_time - @last_reloaded < delay)) || (onchange && !changed?)
|
152
159
|
end
|
153
160
|
|