requirer 0.0.2 → 0.0.3
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/README.md +2 -0
- data/lib/requirer.rb +10 -7
- data/lib/requirer/version.rb +1 -1
- data/spec/dirs_to_require/dir_depth_2/depth0.rb +1 -0
- data/spec/dirs_to_require/dir_depth_2/depth1/depth1.rb +1 -0
- data/spec/dirs_to_require/dir_depth_3/depth1/depth1.rb +1 -1
- data/spec/dirs_to_require/dir_depth_3/depth1/depth2/depth2b.rb +1 -0
- data/spec/dirs_to_require/file_to_find.rb +1 -0
- data/spec/requirer_spec.rb +41 -6
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af3117f038d7d486d08e0756badfacb06156e805
|
4
|
+
data.tar.gz: 1d771ef71986d64ee96f56c071d26ec72ad1034e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40cda14f8637161c0e8823bb751aa475071cb141ecc6345bd648787dfcd4a96f212519b89b42cfbeb5f6268979d5edfad47d1bea6442f41888a7222eb77b59e5
|
7
|
+
data.tar.gz: 6ea91652c1d67b5a722b0600314ffed2a6371a33385d56f78a656df79f76202209b7fe390cc2d8b831b7db844c3f588d861a91baf60079ea5056b69105b0bc04
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/brianmd/requirer) [](http://badge.fury.io/rb/requirer) [](https://coveralls.io/r/brianmd/requirer)
|
2
|
+
|
1
3
|
# Requirer
|
2
4
|
|
3
5
|
- Perform #require on every ruby file in a directory.
|
data/lib/requirer.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative "requirer/version"
|
|
3
3
|
module Requirer
|
4
4
|
class DirUtilsException < StandardError ; end
|
5
5
|
|
6
|
-
def
|
6
|
+
def require_dir_tree(path)
|
7
7
|
# "dir_tree #{path}".logit
|
8
8
|
path = find_dir_with(path, $LOAD_PATH)
|
9
9
|
on_dir_tree(path) do |dir_path|
|
@@ -21,7 +21,7 @@ module Requirer
|
|
21
21
|
return nil unless path
|
22
22
|
|
23
23
|
# "requiring_absolute_dir #{path}".logit
|
24
|
-
Dir["#{path}/[^_]*.rb"].each do |file|
|
24
|
+
Dir["#{path}/[^_]*.rb"].sort.each do |file|
|
25
25
|
next unless File.file?(file)
|
26
26
|
# "requiring #{file}".logit
|
27
27
|
require file
|
@@ -29,24 +29,27 @@ module Requirer
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def find_dir_with(path, search_dirs=$LOAD_PATH)
|
32
|
-
|
32
|
+
fail DirUtilsException.new("No such path: #{path}") unless path
|
33
33
|
path = path.to_s
|
34
34
|
return path if path[0]=='/'
|
35
35
|
search_dirs.each do |dir|
|
36
36
|
dirname = File.expand_path(path, dir)
|
37
37
|
return dirname if File.directory?(dirname)
|
38
38
|
end
|
39
|
-
|
39
|
+
fail DirUtilsException.new("No such path: #{path}")
|
40
40
|
end
|
41
41
|
|
42
42
|
def find_file_with(path, search_dirs=$LOAD_PATH)
|
43
|
-
|
44
|
-
|
43
|
+
fail DirUtilsException.new("No such path: #{path}") unless path
|
44
|
+
if path[0]=='/'
|
45
|
+
fail DirUtilsException.new("No such path: #{path}") unless File.exists?(path)
|
46
|
+
return path
|
47
|
+
end
|
45
48
|
search_dirs.each do |dir|
|
46
49
|
filename = File.expand_path(path, dir)
|
47
50
|
return filename if File.file?(filename)
|
48
51
|
end
|
49
|
-
|
52
|
+
fail DirUtilsException.new("No such path: #{path}")
|
50
53
|
end
|
51
54
|
|
52
55
|
def where_is?(path)
|
data/lib/requirer/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
$bucket << 'depth_zero'
|
@@ -0,0 +1 @@
|
|
1
|
+
$bucket << 'depth_one'
|
@@ -1 +1 @@
|
|
1
|
-
$bucket << 'depth_one(
|
1
|
+
$bucket << 'depth_one(3)'
|
@@ -0,0 +1 @@
|
|
1
|
+
$bucket << 'depth_two,b'
|
@@ -0,0 +1 @@
|
|
1
|
+
$bucket << 'found file'
|
data/spec/requirer_spec.rb
CHANGED
@@ -6,29 +6,64 @@ $LOAD_PATH.unshift 'spec/dirs_to_require'
|
|
6
6
|
describe Requirer do
|
7
7
|
before { $bucket = [] }
|
8
8
|
|
9
|
+
describe 'require a single directory' do
|
10
|
+
it 'file is loaded' do
|
11
|
+
require_dir 'dir_depth_2'
|
12
|
+
expect($bucket).to eq(['depth_zero'])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
9
16
|
describe 'require directory with depth 1' do
|
10
17
|
it 'file is loaded' do
|
11
|
-
|
18
|
+
require_dir_tree 'dir_depth_1'
|
12
19
|
expect($bucket).to eq(['depth_one'])
|
13
20
|
end
|
14
21
|
|
15
22
|
it 'file is loaded only once even though required twice' do
|
16
|
-
|
17
|
-
|
23
|
+
require_dir_tree 'dir_depth_1_only'
|
24
|
+
require_dir_tree 'dir_depth_1_only'
|
18
25
|
expect($bucket).to eq(['depth_one'])
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
22
29
|
describe 'files in each level of directory tree is loaded' do
|
23
30
|
it 'is breadth first' do
|
24
|
-
|
25
|
-
expect($bucket).to eq(['depth_one(
|
31
|
+
require_dir_tree 'dir_depth_3'
|
32
|
+
expect($bucket).to eq(['depth_one(3)', 'depth_two', 'depth_two,b', 'depth_three'])
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
describe 'require non-existent directory' do
|
30
37
|
it 'raises an error' do
|
31
|
-
expect{
|
38
|
+
expect{ require_dir_tree('nobody-is-home') }.to raise_error(DirUtilsException)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'where_is works' do
|
43
|
+
it 'finds file_to_find.rb' do
|
44
|
+
expect(find_file_with('file_to_find.rb').split('/').last).to eq('file_to_find.rb')
|
45
|
+
expect(where_is?('file_to_find.rb').split('/').last).to eq('file_to_find.rb')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'finds file with directory as part of the requested path' do
|
49
|
+
expect(where_is?('dir_depth_1/depth1.rb').split('/').last).to eq('depth1.rb')
|
50
|
+
expect(where_is?('dir_depth_1/depth1.rb').split('/')[-2]).to eq('dir_depth_1')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'finds file with directory as part of the requested path' do
|
54
|
+
filename = File.expand_path("../dirs_to_require/dir_depth_1/depth1.rb", __FILE__)
|
55
|
+
found_filename = where_is?(filename)
|
56
|
+
expect(found_filename[0]).to eq('/')
|
57
|
+
expect(found_filename.split('/').last).to eq('depth1.rb')
|
58
|
+
expect(found_filename.split('/')[-2]).to eq('dir_depth_1')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'raises error on bad path' do
|
62
|
+
expect{ where_is?('asdf') }.to raise_error(DirUtilsException)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'raises error on bad absolute path' do
|
66
|
+
expect{ where_is?('/asdf') }.to raise_error(DirUtilsException)
|
32
67
|
end
|
33
68
|
end
|
34
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: requirer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Murphy-Dye
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,9 +170,13 @@ files:
|
|
170
170
|
- requirer.gemspec
|
171
171
|
- spec/dirs_to_require/dir_depth_1/depth1.rb
|
172
172
|
- spec/dirs_to_require/dir_depth_1_only/depth1.rb
|
173
|
+
- spec/dirs_to_require/dir_depth_2/depth0.rb
|
174
|
+
- spec/dirs_to_require/dir_depth_2/depth1/depth1.rb
|
173
175
|
- spec/dirs_to_require/dir_depth_3/depth1/depth1.rb
|
174
176
|
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth2.rb
|
177
|
+
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth2b.rb
|
175
178
|
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth3/depth3.rb
|
179
|
+
- spec/dirs_to_require/file_to_find.rb
|
176
180
|
- spec/requirer_spec.rb
|
177
181
|
- spec/spec_helper.rb
|
178
182
|
homepage: ''
|
@@ -202,8 +206,12 @@ summary: Require all files in a directory tree
|
|
202
206
|
test_files:
|
203
207
|
- spec/dirs_to_require/dir_depth_1/depth1.rb
|
204
208
|
- spec/dirs_to_require/dir_depth_1_only/depth1.rb
|
209
|
+
- spec/dirs_to_require/dir_depth_2/depth0.rb
|
210
|
+
- spec/dirs_to_require/dir_depth_2/depth1/depth1.rb
|
205
211
|
- spec/dirs_to_require/dir_depth_3/depth1/depth1.rb
|
206
212
|
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth2.rb
|
213
|
+
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth2b.rb
|
207
214
|
- spec/dirs_to_require/dir_depth_3/depth1/depth2/depth3/depth3.rb
|
215
|
+
- spec/dirs_to_require/file_to_find.rb
|
208
216
|
- spec/requirer_spec.rb
|
209
217
|
- spec/spec_helper.rb
|