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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73f6ff42577565773f43c6d8089f35c4fdce994c
4
- data.tar.gz: 65e7a40ff8248c7fddc86d895360077ce6fc16fd
3
+ metadata.gz: 16551c2344afe661a841af495ae36fc631de4c4c
4
+ data.tar.gz: cda47b63ff8f825edac189b39d1ef6bbb1edd093
5
5
  SHA512:
6
- metadata.gz: 1fd10e677eebbc4d7f08c1d284b40936912f6c71ba49bd747e778f5e25f68dd585f2f87d6592856178beea703e5b4c56f2d4684e5645cb3ef259511ea2d17c4a
7
- data.tar.gz: 43323abf4020359ce4fb2f59132e7dc1abe53fb470120310d1cff8459f3d64505ce9379b44363c9b49ad7dbcaffbddaffb0a13f0a084d73e2c9346df2e828e96
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
@@ -1,3 +1,3 @@
1
1
  class AutoReloader
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
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=, :unload!
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 = true
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto_reloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Rosenfeld Rosas