require_all 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +20 -13
- data/LICENSE +58 -58
- data/README.textile +129 -83
- data/Rakefile +11 -11
- data/lib/require_all.rb +277 -125
- data/require_all.gemspec +22 -26
- data/spec/autoload_shared.rb +78 -0
- data/spec/autoload_spec.rb +59 -0
- data/spec/fixtures/autoloaded/module1/a.rb +6 -0
- data/spec/fixtures/autoloaded/module2/longer_name.rb +6 -0
- data/spec/fixtures/autoloaded/module2/module3/b.rb +8 -0
- data/spec/fixtures/autoloaded/with_wrong_module.rb +4 -0
- data/spec/fixtures/autoloaded_rel/modules/module1/first.rb +6 -0
- data/spec/fixtures/autoloaded_rel/modules/module2/second.rb +6 -0
- data/spec/fixtures/autoloaded_rel/modules/zero.rb +6 -0
- data/spec/fixtures/relative/a.rb +1 -1
- data/spec/fixtures/relative/b/b.rb +4 -4
- data/spec/fixtures/relative/c/c.rb +1 -1
- data/spec/fixtures/relative/d/d.rb +8 -0
- data/spec/fixtures/resolvable/c.rb +5 -1
- data/spec/load_spec.rb +50 -0
- data/spec/require_shared.rb +68 -0
- data/spec/require_spec.rb +39 -0
- data/spec/spec_helper.rb +29 -0
- metadata +35 -9
- data/spec/require_all_spec.rb +0 -57
data/require_all.gemspec
CHANGED
@@ -1,26 +1,22 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
GEMSPEC = Gem::Specification.new do |s|
|
4
|
-
s.name = "require_all"
|
5
|
-
s.version = "1.
|
6
|
-
s.authors = "Tony Arcieri"
|
7
|
-
s.email = "
|
8
|
-
s.date = "
|
9
|
-
s.summary = "A wonderfully simple way to load your code"
|
10
|
-
s.platform = Gem::Platform::RUBY
|
11
|
-
|
12
|
-
# Gem contents
|
13
|
-
s.files = Dir.glob("{lib,spec}/**/*") + ['Rakefile', 'require_all.gemspec']
|
14
|
-
|
15
|
-
# RubyForge info
|
16
|
-
s.homepage = "http://github.com/
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
|
23
|
-
|
24
|
-
# Extensions
|
25
|
-
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
26
|
-
end
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
GEMSPEC = Gem::Specification.new do |s|
|
4
|
+
s.name = "require_all"
|
5
|
+
s.version = "1.2.0"
|
6
|
+
s.authors = ["Jarmo Pertman", "Tony Arcieri"]
|
7
|
+
s.email = "jarmo.p@gmail.com"
|
8
|
+
s.date = "2010-09-14"
|
9
|
+
s.summary = "A wonderfully simple way to load your code"
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
|
12
|
+
# Gem contents
|
13
|
+
s.files = Dir.glob("{lib,spec}/**/*") + ['Rakefile', 'require_all.gemspec']
|
14
|
+
|
15
|
+
# RubyForge info
|
16
|
+
s.homepage = "http://github.com/jarmo/require_all"
|
17
|
+
|
18
|
+
# RDoc settings
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.rdoc_options = %w(--title require_all --main README.textile --line-numbers)
|
21
|
+
s.extra_rdoc_files = ["LICENSE", "README.textile", "CHANGES"]
|
22
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# difference between "#require_all syntactic sugar" is the
|
2
|
+
# need to specify :base_dir if performing autoloading below the top-level
|
3
|
+
# module directory
|
4
|
+
|
5
|
+
shared_examples_for "#autoload_all syntactic sugar" do
|
6
|
+
before :each do
|
7
|
+
@file_list = [
|
8
|
+
"#{@base_dir}/module1/a.rb",
|
9
|
+
"#{@base_dir}/module2/longer_name.rb",
|
10
|
+
"#{@base_dir}/module2/module3/b.rb"
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
it "accepts files with and without extensions" do
|
15
|
+
should_not be_loaded("Autoloaded::Module2::LongerName")
|
16
|
+
send(@method, @base_dir + '/module2/longer_name', :base_dir => @autoload_base_dir).should be_true
|
17
|
+
should be_loaded("Autoloaded::Module2::LongerName")
|
18
|
+
|
19
|
+
should_not be_loaded("Autoloaded::Module1::A")
|
20
|
+
send(@method, @base_dir + '/module1/a.rb', :base_dir => @autoload_base_dir).should be_true
|
21
|
+
should be_loaded("Autoloaded::Module1::A")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "accepts lists of files" do
|
25
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
26
|
+
"Autoloaded::Module2::Module3::B")
|
27
|
+
send(@method, @file_list, :base_dir => @autoload_base_dir).should be_true
|
28
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
29
|
+
"Autoloaded::Module2::Module3::B")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "is totally cool with a splatted list of arguments" do
|
33
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
34
|
+
"Autoloaded::Module2::Module3::B")
|
35
|
+
send(@method, *(@file_list << {:base_dir => @autoload_base_dir})).should be_true
|
36
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
37
|
+
"Autoloaded::Module2::Module3::B")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "will load all .rb files under a directory without a trailing slash" do
|
41
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
42
|
+
"Autoloaded::Module2::Module3::B")
|
43
|
+
send(@method, @base_dir, :base_dir => @autoload_base_dir).should be_true
|
44
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
45
|
+
"Autoloaded::Module2::Module3::B")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "will load all .rb files under a directory with a trailing slash" do
|
49
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
50
|
+
"Autoloaded::Module2::Module3::B")
|
51
|
+
send(@method, "#{@base_dir}/", :base_dir => @autoload_base_dir).should be_true
|
52
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
53
|
+
"Autoloaded::Module2::Module3::B")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "will load all files specified by a glob" do
|
57
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
58
|
+
"Autoloaded::Module2::Module3::B")
|
59
|
+
send(@method, "#{@base_dir}/**/*.rb", :base_dir => @autoload_base_dir).should be_true
|
60
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
61
|
+
"Autoloaded::Module2::Module3::B")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns false if an empty input was given" do
|
65
|
+
send(@method, [])
|
66
|
+
send(@method, []).should be_false
|
67
|
+
send(@method).should be_false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raises LoadError if no file or directory found" do
|
71
|
+
lambda {send(@method, "not_found")}.should raise_error(LoadError)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "raises LoadError if :base_dir doesn't exist" do
|
75
|
+
lambda {send(@method, @base_dir, :base_dir => @base_dir + "/non_existing_dir")}.
|
76
|
+
should raise_exception(LoadError)
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/autoload_shared.rb'
|
3
|
+
|
4
|
+
describe "autoload_all" do
|
5
|
+
it "provides require_all functionality by using 'autoload' instead of 'require'" do
|
6
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
7
|
+
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded"
|
8
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "doesn't autoload files with wrong module names" do
|
12
|
+
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded"
|
13
|
+
should_not be_loaded("Autoloaded::WrongModule::WithWrongModule", "WrongModule::WithWrongModule")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "needs to specify base_dir for autoloading if loading something from under top-level module directory" do
|
17
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
18
|
+
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded/module1"
|
19
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
20
|
+
|
21
|
+
autoload_all File.dirname(__FILE__) + "/fixtures/autoloaded/module1",
|
22
|
+
:base_dir => File.dirname(__FILE__) + "/fixtures/autoloaded"
|
23
|
+
should be_loaded("Autoloaded::Module1::A")
|
24
|
+
should_not be_loaded("Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:all) do
|
28
|
+
@base_dir = File.dirname(__FILE__) + '/fixtures/autoloaded'
|
29
|
+
@method = :autoload_all
|
30
|
+
@autoload_base_dir = @base_dir
|
31
|
+
end
|
32
|
+
it_should_behave_like "#autoload_all syntactic sugar"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "autoload_rel" do
|
36
|
+
it "provides autoload_all functionality relative to the current file" do
|
37
|
+
should_not be_loaded("Modules::Module1::First", "Modules::Module2::Second", "Modules::Zero")
|
38
|
+
require File.dirname(__FILE__) + '/fixtures/autoloaded_rel/modules/zero'
|
39
|
+
should be_loaded("Modules::Module1::First", "Modules::Module2::Second", "Modules::Zero")
|
40
|
+
end
|
41
|
+
|
42
|
+
it "needs to specify base_dir for autoloading if loading something from under top-level module directory" do
|
43
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
44
|
+
autoload_rel "./fixtures/autoloaded/module1"
|
45
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
46
|
+
|
47
|
+
autoload_rel "./fixtures/autoloaded/module1",
|
48
|
+
:base_dir => File.dirname(__FILE__) + "/fixtures/autoloaded"
|
49
|
+
should be_loaded("Autoloaded::Module1::A")
|
50
|
+
should_not be_loaded("Autoloaded::Module2::LongerName", "Autoloaded::Module2::Module3::B")
|
51
|
+
end
|
52
|
+
|
53
|
+
before(:all) do
|
54
|
+
@base_dir = './fixtures/autoloaded'
|
55
|
+
@method = :autoload_rel
|
56
|
+
@autoload_base_dir = File.dirname(__FILE__) + "/fixtures/autoloaded"
|
57
|
+
end
|
58
|
+
it_should_behave_like "#autoload_all syntactic sugar"
|
59
|
+
end
|
data/spec/fixtures/relative/a.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
class RelativeA
|
1
|
+
class RelativeA
|
2
2
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require_rel '../a'
|
2
|
-
require_rel '../c'
|
3
|
-
|
4
|
-
class RelativeB
|
1
|
+
require_rel '../a'
|
2
|
+
require_rel '../c'
|
3
|
+
|
4
|
+
class RelativeB
|
5
5
|
end
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class RelativeC
|
1
|
+
class RelativeC
|
2
2
|
end
|
data/spec/load_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/require_shared.rb'
|
3
|
+
|
4
|
+
describe "load_all" do
|
5
|
+
it "provides require_all functionality but using 'load' instead of 'require'" do
|
6
|
+
require_all File.dirname(__FILE__) + '/fixtures/resolvable'
|
7
|
+
C.new.should be_cool
|
8
|
+
|
9
|
+
class C
|
10
|
+
def cool?
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
C.new.should_not be_cool
|
15
|
+
|
16
|
+
load_all File.dirname(__FILE__) + '/fixtures/resolvable'
|
17
|
+
C.new.should be_cool
|
18
|
+
end
|
19
|
+
|
20
|
+
before(:all) do
|
21
|
+
@base_dir = File.dirname(__FILE__) + '/fixtures/autoloaded'
|
22
|
+
@method = :load_all
|
23
|
+
end
|
24
|
+
it_should_behave_like "#require_all syntactic sugar"
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "load_rel" do
|
28
|
+
it "provides load_all functionality relative to the current file" do
|
29
|
+
require File.dirname(__FILE__) + '/fixtures/relative/d/d'
|
30
|
+
|
31
|
+
should be_loaded("RelativeA", "RelativeC", "RelativeD")
|
32
|
+
RelativeD.new.should be_ok
|
33
|
+
|
34
|
+
class RelativeD
|
35
|
+
def ok?
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
RelativeD.new.should_not be_ok
|
40
|
+
|
41
|
+
load File.dirname(__FILE__) + '/fixtures/relative/d/d.rb'
|
42
|
+
RelativeD.new.should be_ok
|
43
|
+
end
|
44
|
+
|
45
|
+
before(:all) do
|
46
|
+
@base_dir = './fixtures/autoloaded'
|
47
|
+
@method = :load_rel
|
48
|
+
end
|
49
|
+
it_should_behave_like "#require_all syntactic sugar"
|
50
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
shared_examples_for "#require_all syntactic sugar" do
|
2
|
+
before :each do
|
3
|
+
@file_list = [
|
4
|
+
"#{@base_dir}/module1/a.rb",
|
5
|
+
"#{@base_dir}/module2/longer_name.rb",
|
6
|
+
"#{@base_dir}/module2/module3/b.rb"
|
7
|
+
]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "accepts files with and without extensions" do
|
11
|
+
should_not be_loaded("Autoloaded::Module2::LongerName")
|
12
|
+
send(@method, @base_dir + '/module2/longer_name').should be_true
|
13
|
+
should be_loaded("Autoloaded::Module2::LongerName")
|
14
|
+
|
15
|
+
should_not be_loaded("Autoloaded::Module1::A")
|
16
|
+
send(@method, @base_dir + '/module1/a.rb').should be_true
|
17
|
+
should be_loaded("Autoloaded::Module1::A")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "accepts lists of files" do
|
21
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
22
|
+
"Autoloaded::Module2::Module3::B")
|
23
|
+
send(@method, @file_list).should be_true
|
24
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
25
|
+
"Autoloaded::Module2::Module3::B")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is totally cool with a splatted list of arguments" do
|
29
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
30
|
+
"Autoloaded::Module2::Module3::B")
|
31
|
+
send(@method, *@file_list).should be_true
|
32
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
33
|
+
"Autoloaded::Module2::Module3::B")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "will load all .rb files under a directory without a trailing slash" do
|
37
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
38
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
39
|
+
send(@method, @base_dir).should be_true
|
40
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
41
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "will load all .rb files under a directory with a trailing slash" do
|
45
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
46
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
47
|
+
send(@method, "#{@base_dir}/").should be_true
|
48
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
49
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "will load all files specified by a glob" do
|
53
|
+
should_not be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
54
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
55
|
+
send(@method, "#{@base_dir}/**/*.rb").should be_true
|
56
|
+
should be_loaded("Autoloaded::Module1::A", "Autoloaded::Module2::LongerName",
|
57
|
+
"Autoloaded::Module2::Module3::B", "WrongModule::WithWrongModule")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns false if an empty input was given" do
|
61
|
+
send(@method, []).should be_false
|
62
|
+
send(@method).should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "throws LoadError if no file or directory found" do
|
66
|
+
lambda {send(@method, "not_found")}.should raise_error(LoadError)
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/require_shared.rb'
|
3
|
+
|
4
|
+
describe "require_all" do
|
5
|
+
describe "dependency resolution" do
|
6
|
+
it "handles load ordering when dependencies are resolvable" do
|
7
|
+
require_all File.dirname(__FILE__) + '/fixtures/resolvable/*.rb'
|
8
|
+
|
9
|
+
should be_loaded("A", "B", "C", "D")
|
10
|
+
end
|
11
|
+
|
12
|
+
it "raises NameError if dependencies can't be resolved" do
|
13
|
+
proc do
|
14
|
+
require_all File.dirname(__FILE__) + '/fixtures/unresolvable/*.rb'
|
15
|
+
end.should raise_error(NameError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:all) do
|
20
|
+
@base_dir = File.dirname(__FILE__) + '/fixtures/autoloaded'
|
21
|
+
@method = :require_all
|
22
|
+
end
|
23
|
+
it_should_behave_like "#require_all syntactic sugar"
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "require_rel" do
|
27
|
+
it "provides require_all functionality relative to the current file" do
|
28
|
+
require File.dirname(__FILE__) + '/fixtures/relative/b/b'
|
29
|
+
|
30
|
+
should be_loaded("RelativeA", "RelativeB", "RelativeC")
|
31
|
+
should_not be_loaded("RelativeD")
|
32
|
+
end
|
33
|
+
|
34
|
+
before(:all) do
|
35
|
+
@base_dir = './fixtures/autoloaded'
|
36
|
+
@method = :require_rel
|
37
|
+
end
|
38
|
+
it_should_behave_like "#require_all syntactic sugar"
|
39
|
+
end
|