load_path_find 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -26,4 +26,16 @@ And now, even more awesome!
26
26
 
27
27
  .. adds the current path to the start of the <tt>$LOAD_PATH</tt>
28
28
 
29
- And one more clever trick, <tt>Kernel#require_all</tt>, lets you require all matching files.
29
+ And one more clever trick, <tt>Kernel#require_all</tt>, lets you require all matching files.
30
+
31
+ Also, there is <tt>Kernel#require_next</tt> which can be used to monkey patch on require:
32
+
33
+ # my_extension/stringio.rb
34
+ require_next "stringio"
35
+ StringIO.class_eval do
36
+ # insert evil stuff here
37
+ end
38
+
39
+ # my_extension/setup.rb
40
+ $LOAD_PATH.add_current!
41
+ require "some_code_not_owned_by_me_maybe_requiring_stringio_oh_how_will_i_fool_them_all"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -6,9 +6,10 @@ $LOAD_PATH.instance_eval do
6
6
  nil
7
7
  end
8
8
 
9
- def find_all_files(file)
9
+ def find_all_files(file, ext = nil)
10
+ file += ext if ext and File.extname(file) != ext
10
11
  inject([]){|ary, path|
11
- target = File.join(path, file)
12
+ target = File.expand_path(file, path)
12
13
  if File.readable?(target)
13
14
  ary << target
14
15
  yield target if block_given?
@@ -29,6 +30,19 @@ end
29
30
 
30
31
  module Kernel
31
32
  def require_all(req)
32
- $LOAD_PATH.find_all_files(File.extname(req) == '.rb' ? req : "#{req}.rb") { |file| require file }
33
+ $LOAD_PATH.find_all_files(req, ".rb") { |file| require file }
34
+ end
35
+
36
+ def require_next(req)
37
+ found, current = false, File.expand_path(caller.first[/^[^:]+/])
38
+ $LOAD_PATH.find_all_files(req, ".rb") do |file|
39
+ if found
40
+ $LOADED_FEATURES << req
41
+ return require(file)
42
+ else
43
+ found = current == file
44
+ end
45
+ end
46
+ require req
33
47
  end
34
48
  end
@@ -0,0 +1,2 @@
1
+ $test2 = 1
2
+ require_next "test2"
@@ -0,0 +1 @@
1
+ $test2 = 2 if $test2 == 1
@@ -10,8 +10,8 @@ describe 'load path find' do
10
10
  end
11
11
 
12
12
  it "should find a directory on the load path" do
13
- target = File.join('..', 'dir1')
14
- $:.find_file(target)[-target.size, target.size].should == target
13
+ target = "data/dir1"
14
+ $:.find_file("../dir1")[-target.size, target.size].should == target
15
15
  end
16
16
 
17
17
  it "should find the first file when its ambigious" do
@@ -53,5 +53,10 @@ describe 'load path find' do
53
53
  $state1.should be_true
54
54
  $state2.should be_true
55
55
  end
56
+
57
+ it "should require_next" do
58
+ require 'test2'
59
+ $test2.should == 2
60
+ end
56
61
 
57
62
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: load_path_find
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 5
9
+ version: 0.0.5
5
10
  platform: ruby
6
11
  authors:
7
12
  - Joshua Hull
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-17 00:00:00 -05:00
17
+ date: 2010-04-05 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: dirge
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 0
30
+ - 3
23
31
  version: 0.0.3
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description: Convenient way to find stuff on the load path.
26
35
  email: joshbuddy@gmail.com
27
36
  executables: []
@@ -37,8 +46,10 @@ files:
37
46
  - lib/load_path_find.rb
38
47
  - spec/data/dir1/file1
39
48
  - spec/data/dir1/test.rb
49
+ - spec/data/dir1/test2.rb
40
50
  - spec/data/dir2/file1
41
51
  - spec/data/dir2/test.rb
52
+ - spec/data/dir2/test2.rb
42
53
  - spec/load_path_find_spec.rb
43
54
  - spec/spec.opts
44
55
  has_rdoc: true
@@ -54,22 +65,26 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
65
  requirements:
55
66
  - - ">="
56
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
57
70
  version: "0"
58
- version:
59
71
  required_rubygems_version: !ruby/object:Gem::Requirement
60
72
  requirements:
61
73
  - - ">="
62
74
  - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
63
77
  version: "0"
64
- version:
65
78
  requirements: []
66
79
 
67
80
  rubyforge_project:
68
- rubygems_version: 1.3.5
81
+ rubygems_version: 1.3.6
69
82
  signing_key:
70
83
  specification_version: 3
71
84
  summary: Convenient way to find stuff on the load path.
72
85
  test_files:
73
86
  - spec/data/dir1/test.rb
87
+ - spec/data/dir1/test2.rb
74
88
  - spec/data/dir2/test.rb
89
+ - spec/data/dir2/test2.rb
75
90
  - spec/load_path_find_spec.rb