require_all 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES +5 -0
- data/lib/require_all.rb +11 -6
- data/require_all.gemspec +1 -1
- data/spec/autoload_spec.rb +8 -0
- data/spec/fixtures/autoloaded/class1.rb +4 -0
- data/spec/fixtures/autoloaded/class1/c.rb +6 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0acf6c3cfe3c05348dc4f39a44862b3ff9e1588
|
4
|
+
data.tar.gz: dfd83ec51fd0c052866242da84e23ee677baa107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cf536e611f4a5d089be5890d01775628b564051d7c60d9f1827abea02b0b4b9eafad8270be8951000612f02d8f4ba0713ce396bc4190a712a9cddf30bcb4b0d
|
7
|
+
data.tar.gz: 9108afdd13f81ad242b5e9824ef6eb2477326d4979f1d51bae39739c256eaaa64046f3c1f777a08bde1fc6eacb974bcd70847a316adfde8c5198acb565d426cf
|
data/CHANGES
CHANGED
data/lib/require_all.rb
CHANGED
@@ -72,7 +72,7 @@ module RequireAll
|
|
72
72
|
# Maybe it's an .rb file and the .rb was omitted
|
73
73
|
if File.file?(arg + '.rb')
|
74
74
|
file = arg + '.rb'
|
75
|
-
options[:method] != :autoload ?
|
75
|
+
options[:method] != :autoload ? __require(options[:method], file) : __autoload(file, file, options)
|
76
76
|
return true
|
77
77
|
end
|
78
78
|
|
@@ -105,7 +105,7 @@ module RequireAll
|
|
105
105
|
# files can be loaded, indicating unresolvable dependencies.
|
106
106
|
files.each do |file_|
|
107
107
|
begin
|
108
|
-
|
108
|
+
__require(options[:method], file_)
|
109
109
|
rescue NameError => ex
|
110
110
|
failed << file_
|
111
111
|
first_name_error ||= ex
|
@@ -239,6 +239,10 @@ module RequireAll
|
|
239
239
|
|
240
240
|
private
|
241
241
|
|
242
|
+
def __require(method, file)
|
243
|
+
Kernel.send(method, file)
|
244
|
+
end
|
245
|
+
|
242
246
|
def __autoload(file, full_path, options)
|
243
247
|
last_module = "Object" # default constant where namespaces are created into
|
244
248
|
begin
|
@@ -259,15 +263,16 @@ module RequireAll
|
|
259
263
|
without_ext = entry.basename(entry.extname).to_s
|
260
264
|
const = without_ext.split("_").map {|word| word.capitalize}.join
|
261
265
|
|
262
|
-
if entry.directory?
|
263
|
-
mod.class_eval "module #{const} end"
|
264
|
-
last_module += "::#{const}"
|
265
|
-
else
|
266
|
+
if entry.file? || (entry.directory? && entry.sub_ext('.rb').file?)
|
266
267
|
mod.class_eval do
|
267
268
|
puts "autoloading #{mod}::#{const} from #{full_path}" if $DEBUG
|
268
269
|
autoload const, full_path
|
269
270
|
end
|
271
|
+
else
|
272
|
+
mod.class_eval "module #{const} end" if entry.directory?
|
270
273
|
end
|
274
|
+
|
275
|
+
last_module += "::#{const}" if entry.directory?
|
271
276
|
end
|
272
277
|
end
|
273
278
|
|
data/require_all.gemspec
CHANGED
data/spec/autoload_spec.rb
CHANGED
@@ -16,6 +16,14 @@ describe "autoload_all" do
|
|
16
16
|
is_expected.not_to be_loaded("Autoloaded::WrongModule::WithWrongModule", "WrongModule::WithWrongModule")
|
17
17
|
end
|
18
18
|
|
19
|
+
it "autoloads class nested into another class" do
|
20
|
+
is_expected.not_to be_loaded("Autoloaded::Class1", "Autoloaded::Class1::C")
|
21
|
+
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded"
|
22
|
+
is_expected.to be_loaded("Autoloaded::Class1")
|
23
|
+
expect(Autoloaded::Class1).to be_a Class
|
24
|
+
is_expected.to be_loaded("Autoloaded::Class1::C")
|
25
|
+
end
|
26
|
+
|
19
27
|
it "needs to specify base_dir for autoloading if loading something from under top-level module directory" do
|
20
28
|
is_expected.not_to be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
21
29
|
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded/module1"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: require_all
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jarmo Pertman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -73,6 +73,8 @@ files:
|
|
73
73
|
- require_all.gemspec
|
74
74
|
- spec/autoload_shared.rb
|
75
75
|
- spec/autoload_spec.rb
|
76
|
+
- spec/fixtures/autoloaded/class1.rb
|
77
|
+
- spec/fixtures/autoloaded/class1/c.rb
|
76
78
|
- spec/fixtures/autoloaded/module1/a.rb
|
77
79
|
- spec/fixtures/autoloaded/module2/longer_name.rb
|
78
80
|
- spec/fixtures/autoloaded/module2/module3/b.rb
|
@@ -121,13 +123,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
123
|
version: '0'
|
122
124
|
requirements: []
|
123
125
|
rubyforge_project:
|
124
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.6.13
|
125
127
|
signing_key:
|
126
128
|
specification_version: 4
|
127
129
|
summary: A wonderfully simple way to load your code
|
128
130
|
test_files:
|
129
131
|
- spec/autoload_shared.rb
|
130
132
|
- spec/autoload_spec.rb
|
133
|
+
- spec/fixtures/autoloaded/class1.rb
|
134
|
+
- spec/fixtures/autoloaded/class1/c.rb
|
131
135
|
- spec/fixtures/autoloaded/module1/a.rb
|
132
136
|
- spec/fixtures/autoloaded/module2/longer_name.rb
|
133
137
|
- spec/fixtures/autoloaded/module2/module3/b.rb
|