rack-unreloader 1.8.0 → 2.0.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
2
  SHA256:
3
- metadata.gz: f6fefe4d57aa2ea927929699e2a6aba2e8979cea284b0784fee379404b6f1726
4
- data.tar.gz: 3aa21b88447194616e29d1ea2cf1181f102f5d58e6a29f4a11696a83d826a506
3
+ metadata.gz: f60b8ff5b4384a7f55f92c4e851e2589622112228849b63ed7cf520b2e4b4112
4
+ data.tar.gz: e01e616600037edc3eb954dd9cf7fd6c8667fa43b15590ec4bb5041547c5f4af
5
5
  SHA512:
6
- metadata.gz: 6a5fbca1692b66ab4daf1f9b1677b15fb704d28bb972b26fdc15d78918fa37bed04657177438ff2351ba8c60a10105f7e138d869a4ab37fbd9e4143188c5685d
7
- data.tar.gz: 12d9b2d24730e1f41da6089e5995c219af4b636755738405d1404e0be3f4044c8f935bd073ba53d92cada170761f79bfea82235c5b58d9ca6bc1dac1ee1b647f
6
+ metadata.gz: 5da4eebc546fcc8194667ca1c1176574f6299a2bef8b062f24edf09146fc151f234b8119af9c19120f5245a5b921cb6841bba29c4bfc20abdc5d229ac040305a
7
+ data.tar.gz: f7fcb791cb9a0d8f585444ba7bddc4f2ffd80759c4544c8a450c8ebeb38b8620bf24cd05c6a368921c395c9de2ddb1a60f6a31a26a30d76df2d458de35355904
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ = 2.0.0 (2022-06-23)
2
+
3
+ * Fix TypeError being raised when requiring a file results in an error (jeremyevans)
4
+
5
+ * Drop Unreloader#strip_path_prefix (jeremyevans)
6
+
7
+ * Drop Ruby 1.8 support (jeremyevans)
8
+
1
9
  = 1.8.0 (2021-10-15)
2
10
 
3
11
  * Avoid warnings in verbose warning mode on Ruby 3+ (jeremyevans)
data/README.rdoc CHANGED
@@ -253,18 +253,6 @@ decide that instead of specifying the constants, ObjectSpace should be used to
253
253
  automatically determine the constants loaded. You can specify this by having the
254
254
  block return the :ObjectSpace symbol.
255
255
 
256
- == chroot Support
257
-
258
- +Rack::Unreloader#strip_path_prefix+ exists for supporting reloading in
259
- chroot environments, where you chroot an application after it has been fully
260
- loaded, but still want to pick up changes to files inside the chroot. Example:
261
-
262
- Unreloader.strip_path_prefix(Dir.pwd)
263
- Dir.chroot(Dir.pwd)
264
-
265
- Note that Unreloader.strip_path_prefix also strips the path prefix from
266
- $LOADED_FEATURES, as that is necessary for correct operation.
267
-
268
256
  == Usage Outside Rack
269
257
 
270
258
  While +Rack::Unreloader+ is usually in the development of rack applications,
@@ -296,11 +284,9 @@ environment anytime there are any changes) are going to be more robust than
296
284
  this approach, but probably slower. Be aware that you are trading robustness
297
285
  for speed when using this library.
298
286
 
299
- == Implementation Support
287
+ == Ruby Version Support
300
288
 
301
- Rack::Unreloader works correctly on Ruby 1.8.7+, JRuby 9.1+, and Rubinius. It
302
- also works on older versions of JRuby if you use a proc to specify the constants
303
- to unload.
289
+ Rack::Unreloader works correctly on Ruby 1.9.2+ and JRuby 9.1+.
304
290
 
305
291
  == License
306
292
 
@@ -8,9 +8,6 @@ module Rack
8
8
  # Regexp for valid constant names, to prevent code execution.
9
9
  VALID_CONSTANT_NAME_REGEXP = /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/.freeze
10
10
 
11
- # Options hash to force loading of files even if they haven't changed.
12
- FORCE = {:force=>true}.freeze
13
-
14
11
  # Setup the reloader. Supports :logger and :subclasses options, see
15
12
  # Rack::Unloader.new for details.
16
13
  def initialize(opts={})
@@ -55,47 +52,6 @@ module Rack
55
52
  @skip_reload = []
56
53
  end
57
54
 
58
- # Strip the given path prefix from the internal data structures.
59
- def strip_path_prefix(path_prefix)
60
- empty = ''.freeze
61
-
62
- # Strip the path prefix from $LOADED_FEATURES, otherwise the reloading won't work.
63
- # Hopefully a future version of ruby will do this automatically when chrooting.
64
- $LOADED_FEATURES.map!{|s| s.sub(path_prefix, empty)}
65
-
66
- fix_path = lambda do |s|
67
- s.sub(path_prefix, empty)
68
- end
69
-
70
- [@dependency_order, @skip_reload].each do |a|
71
- a.map!(&fix_path)
72
- end
73
-
74
- [@files, @old_entries].each do |hash|
75
- hash.each do |k,h|
76
- h[:features].map!(&fix_path)
77
- end
78
- end
79
-
80
- @monitor_dirs.each_value do |a|
81
- a[1].map!(&fix_path)
82
- end
83
-
84
- @dependencies.each_value do |a|
85
- a.map!(&fix_path)
86
- end
87
-
88
- [@files, @old_entries, @monitor_files, @monitor_dirs, @constants_defined, @dependencies].each do |hash|
89
- hash.keys.each do |k|
90
- if k.start_with?(path_prefix)
91
- hash[fix_path.call(k)] = hash.delete(k)
92
- end
93
- end
94
- end
95
-
96
- nil
97
- end
98
-
99
55
  # Unload all reloadable constants and features, and clear the list
100
56
  # of files to monitor.
101
57
  def clear!
@@ -157,11 +113,7 @@ module Rack
157
113
  return if changed_files.empty?
158
114
 
159
115
  unless @dependencies.empty?
160
- changed_files = reload_files(changed_files)
161
- changed_files.flatten!
162
- changed_files.map!{|f| File.directory?(f) ? Unreloader.ruby_files(f) : f}
163
- changed_files.flatten!
164
- changed_files.uniq!
116
+ changed_files = Unreloader.expand_directory_paths(reload_files(changed_files))
165
117
 
166
118
  order = @dependency_order
167
119
  order &= changed_files
@@ -169,14 +121,14 @@ module Rack
169
121
  end
170
122
 
171
123
  unless @skip_reload.empty?
172
- skip_reload = @skip_reload.map{|f| File.directory?(f) ? Unreloader.ruby_files(f) : f}
173
- skip_reload.flatten!
174
- skip_reload.uniq!
175
- changed_files -= skip_reload
124
+ changed_files -= Unreloader.expand_directory_paths(@skip_reload)
176
125
  end
177
126
 
127
+ changed_files.select! do |file|
128
+ @monitor_files.has_key?(file)
129
+ end
178
130
  changed_files.each do |file|
179
- safe_load(file, FORCE)
131
+ safe_load(file)
180
132
  end
181
133
  end
182
134
 
@@ -200,14 +152,14 @@ module Rack
200
152
  begin
201
153
  safe_load(file, options)
202
154
  rescue NameError, LoadError => error
203
- log "Cyclic dependency reload for #{error}"
155
+ log "Cyclic dependency reload for #{error.class}: #{error.message}"
204
156
  rescue Exception => error
157
+ log "Error: #{error.class}: #{error.message}"
205
158
  break
206
159
  end
207
160
  end
208
161
 
209
162
  if error
210
- log error
211
163
  raise error
212
164
  end
213
165
  end
@@ -301,9 +253,6 @@ module Rack
301
253
  # by the require, and rolling back the constants and features if there
302
254
  # are any errors.
303
255
  def safe_load(file, options={})
304
- return unless @monitor_files.has_key?(file)
305
- return unless options[:force] || file_changed?(file)
306
-
307
256
  prepare(file) # might call #safe_load recursively
308
257
  log "Loading #{file}"
309
258
  begin
@@ -15,20 +15,21 @@ module Rack
15
15
  # in subdirecories if given a directory, and return an array of expanded
16
16
  # paths.
17
17
  def self.expand_directory_paths(paths)
18
- expand_paths(paths).
19
- map{|f| File.directory?(f) ? ruby_files(f) : f}.
20
- flatten
18
+ paths = expand_paths(paths)
19
+ paths.map!{|f| File.directory?(f) ? ruby_files(f) : f}
20
+ paths.flatten!
21
+ paths
21
22
  end
22
23
 
23
24
  # Given the path glob or array of path globs, find all matching files
24
25
  # or directories, and return an array of expanded paths.
25
26
  def self.expand_paths(paths)
26
- Array(paths).
27
- flatten.
28
- map{|path| Dir.glob(path).sort_by{|filename| filename.count('/')}}.
29
- flatten.
30
- map{|path| File.expand_path(path)}.
31
- uniq
27
+ paths = Array(paths).flatten
28
+ paths.map!{|path| Dir.glob(path).sort_by!{|filename| filename.count('/')}}
29
+ paths.flatten!
30
+ paths.map!{|path| File.expand_path(path)}
31
+ paths.uniq!
32
+ paths
32
33
  end
33
34
 
34
35
  # The .rb files in the given directory or any subdirectory.
@@ -62,7 +63,7 @@ module Rack
62
63
  @cooldown = opts.fetch(:cooldown, 1)
63
64
  @handle_reload_errors = opts[:handle_reload_errors]
64
65
  @last = Time.at(0)
65
- Kernel.require 'rack/unreloader/reloader'
66
+ require_relative 'unreloader/reloader'
66
67
  @reloader = Reloader.new(opts)
67
68
  reload!
68
69
  else
@@ -128,17 +129,5 @@ module Rack
128
129
  def reload!
129
130
  @reloader.reload! if @reloader
130
131
  end
131
-
132
- # Strip the given path prefix from all absolute paths used by the
133
- # reloader. This is designed when chrooting an application.
134
- #
135
- # Options:
136
- # :strip_core :: Also strips the path prefix from $LOADED_FEATURES and
137
- # $LOAD_PATH.
138
- def strip_path_prefix(path_prefix, opts={})
139
- if @reloader
140
- @reloader.strip_path_prefix(path_prefix)
141
- end
142
- end
143
132
  end
144
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-unreloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-15 00:00:00.000000000 Z
11
+ date: 2022-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -66,12 +66,8 @@ files:
66
66
  - CHANGELOG
67
67
  - MIT-LICENSE
68
68
  - README.rdoc
69
- - Rakefile
70
69
  - lib/rack/unreloader.rb
71
70
  - lib/rack/unreloader/reloader.rb
72
- - spec/spec_helper.rb
73
- - spec/strip_paths_spec.rb
74
- - spec/unreloader_spec.rb
75
71
  homepage: http://github.com/jeremyevans/rack-unreloader
76
72
  licenses:
77
73
  - MIT
@@ -95,14 +91,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
91
  requirements:
96
92
  - - ">="
97
93
  - !ruby/object:Gem::Version
98
- version: 1.8.7
94
+ version: 1.9.2
99
95
  required_rubygems_version: !ruby/object:Gem::Requirement
100
96
  requirements:
101
97
  - - ">="
102
98
  - !ruby/object:Gem::Version
103
99
  version: '0'
104
100
  requirements: []
105
- rubygems_version: 3.2.22
101
+ rubygems_version: 3.3.7
106
102
  signing_key:
107
103
  specification_version: 4
108
104
  summary: Reload application when files change, unloading constants first
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- require "rake"
2
- require "rake/clean"
3
-
4
- CLEAN.include ["rack-unreloader-*.gem", "rdoc"]
5
-
6
- desc "Build rack-unreloader gem"
7
- task :package=>[:clean] do |p|
8
- sh %{#{FileUtils::RUBY} -S gem build rack-unreloader.gemspec}
9
- end
10
-
11
- ### Specs
12
-
13
- desc "Run specs"
14
- task :spec do
15
- sh "#{FileUtils::RUBY} #{'-w ' if RUBY_VERSION >= '3'}spec/unreloader_spec.rb"
16
- end
17
-
18
- task :default => :spec
19
-
20
- ### RDoc
21
-
22
- RDOC_DEFAULT_OPTS = ["--quiet", "--line-numbers", "--inline-source", '--title', 'Rack::Unreloader: Reload application when files change, unloading constants first']
23
-
24
- begin
25
- gem 'hanna-nouveau'
26
- RDOC_DEFAULT_OPTS.concat(['-f', 'hanna'])
27
- rescue Gem::LoadError
28
- end
29
-
30
- rdoc_task_class = begin
31
- require "rdoc/task"
32
- RDoc::Task
33
- rescue LoadError
34
- require "rake/rdoctask"
35
- Rake::RDocTask
36
- end
37
-
38
- RDOC_OPTS = RDOC_DEFAULT_OPTS + ['--main', 'README.rdoc']
39
-
40
- rdoc_task_class.new do |rdoc|
41
- rdoc.rdoc_dir = "rdoc"
42
- rdoc.options += RDOC_OPTS
43
- rdoc.rdoc_files.add %w"README.rdoc CHANGELOG MIT-LICENSE lib/**/*.rb"
44
- end
45
-
data/spec/spec_helper.rb DELETED
@@ -1,87 +0,0 @@
1
- require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/rack/unreloader')
2
- require 'rubygems'
3
- $: << 'lib'
4
- ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
5
- gem 'minitest'
6
- require 'minitest/global_expectations/autorun'
7
- require 'minitest/hooks'
8
-
9
- module ModifiedAt
10
- def set_modified_time(file, time)
11
- time = Time.now + time if time.is_a?(Integer)
12
- modified_times[File.expand_path(file)] = time
13
- end
14
-
15
- def modified_times
16
- @modified_times ||= {}
17
- end
18
-
19
- private
20
-
21
- def modified_at(file)
22
- modified_times[file] || super
23
- end
24
- end
25
-
26
- class Minitest::Spec
27
- def code(i)
28
- "class App; class << self; def call(env) @a end; alias call call; end; @a ||= []; @a << #{i}; end"
29
- end
30
-
31
- def update_app(code, file=@filename)
32
- if ru.reloader
33
- ru.reloader.set_modified_time(File.dirname(file), @i += 1) unless File.file?(file)
34
- ru.reloader.set_modified_time(file, @i += 1)
35
- end
36
- File.open(file, 'wb'){|f| f.write(code)}
37
- end
38
-
39
- def file_delete(file)
40
- if ru.reloader
41
- ru.reloader.set_modified_time(File.dirname(file), @i += 1)
42
- end
43
- File.delete(file)
44
- end
45
-
46
- def logger
47
- return @logger if @logger
48
- @logger = []
49
- def @logger.method_missing(meth, log)
50
- self << log
51
- end
52
- @logger
53
- end
54
-
55
- def base_ru(opts={})
56
- block = opts[:block] || proc{App}
57
- @ru = Rack::Unreloader.new({:logger=>logger, :cooldown=>0}.merge(opts), &block)
58
- @ru.reloader.extend ModifiedAt if @ru.reloader
59
- Object.const_set(:RU, @ru)
60
- end
61
-
62
- def ru(opts={})
63
- return @ru if @ru
64
- base_ru(opts)
65
- update_app(opts[:code]||code(1))
66
- @ru.require @filename
67
- @ru
68
- end
69
-
70
- def log_match(*logs)
71
- @logger.length.must_equal logs.length
72
- logs.zip(@logger).each{|l, log| l.is_a?(String) ? log.must_equal(l) : log.must_match(l)}
73
- end
74
-
75
- before do
76
- @i = 0
77
- @filename = 'spec/app.rb'
78
- end
79
-
80
- after do
81
- ru.reloader.clear! if ru.reloader
82
- Object.send(:remove_const, :RU)
83
- Object.send(:remove_const, :App) if defined?(::App)
84
- Object.send(:remove_const, :App2) if defined?(::App2)
85
- Dir['spec/app*.rb'].each{|f| File.delete(f)}
86
- end
87
- end