requirer 0.0.2 → 0.0.3

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: fb3a02ffae64a6c0e5cbc641c2e1b0a01d8c2d1e
4
- data.tar.gz: 63e600c6c5b35a9cd137f6cd19d67e2ed486def3
3
+ metadata.gz: af3117f038d7d486d08e0756badfacb06156e805
4
+ data.tar.gz: 1d771ef71986d64ee96f56c071d26ec72ad1034e
5
5
  SHA512:
6
- metadata.gz: 339112bb76cbeb951b2674c99d96b0cb6105fabd42a97d2073485d7a2e9796cf5d785f0afa923340896523c9fce96e939f664c07813c89930d7d17b6c061bdbf
7
- data.tar.gz: 950a0570b94340255c9cb8a6994c965e91f04b1af49825b083350be5d156d81dee243952330e5c445367bd9375dab16944d8379919ba7ca9c8e091a80cf60c4f
6
+ metadata.gz: 40cda14f8637161c0e8823bb751aa475071cb141ecc6345bd648787dfcd4a96f212519b89b42cfbeb5f6268979d5edfad47d1bea6442f41888a7222eb77b59e5
7
+ data.tar.gz: 6ea91652c1d67b5a722b0600314ffed2a6371a33385d56f78a656df79f76202209b7fe390cc2d8b831b7db844c3f588d861a91baf60079ea5056b69105b0bc04
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://api.travis-ci.org/brianmd/requirer.png?branch=master)](https://travis-ci.org/brianmd/requirer) [![Gem Version](https://badge.fury.io/rb/requirer.png)](http://badge.fury.io/rb/requirer) [![Coverage Status](https://coveralls.io/repos/brianmd/requirer/badge.png)](https://coveralls.io/r/brianmd/requirer)
2
+
1
3
  # Requirer
2
4
 
3
5
  - Perform #require on every ruby file in a directory.
@@ -3,7 +3,7 @@ require_relative "requirer/version"
3
3
  module Requirer
4
4
  class DirUtilsException < StandardError ; end
5
5
 
6
- def dir_tree(path)
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
- raise DirUtilsException.new("No such path: #{path}") unless path
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
- raise DirUtilsException.new("No such path: #{path}")
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
- raise DirUtilsException.new("No such path: #{path}") unless path
44
- return path if path[0]=='/'
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
- raise DirUtilsException.new("No such path: #{path}")
52
+ fail DirUtilsException.new("No such path: #{path}")
50
53
  end
51
54
 
52
55
  def where_is?(path)
@@ -1,3 +1,3 @@
1
1
  module Requirer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1 @@
1
+ $bucket << 'depth_zero'
@@ -0,0 +1 @@
1
+ $bucket << 'depth_one'
@@ -1 +1 @@
1
- $bucket << 'depth_one(2)'
1
+ $bucket << 'depth_one(3)'
@@ -0,0 +1 @@
1
+ $bucket << 'depth_two,b'
@@ -0,0 +1 @@
1
+ $bucket << 'found file'
@@ -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
- dir_tree 'dir_depth_1'
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
- dir_tree 'dir_depth_1_only'
17
- dir_tree 'dir_depth_1_only'
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
- dir_tree 'dir_depth_3'
25
- expect($bucket).to eq(['depth_one(2)', 'depth_two', 'depth_three'])
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{ dir_tree('nobody-is-home') }.to raise_error(DirUtilsException)
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.2
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-15 00:00:00.000000000 Z
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