load_path_find 0.0.1
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.
- data/README.rdoc +17 -0
- data/Rakefile +28 -0
- data/VERSION +1 -0
- data/lib/load_path_find.rb +18 -0
- data/spec/data/dir1/file1 +0 -0
- data/spec/data/dir2/file1 +0 -0
- data/spec/load_path_find_spec.rb +39 -0
- data/spec/spec.opts +7 -0
- metadata +62 -0
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= Load Path Find
|
2
|
+
|
3
|
+
Useful tools for looking for files on the $LOAD_PATH
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
> require 'load_path_find'
|
8
|
+
> $LOAD_PATH.find_file('set.rb')
|
9
|
+
< "/opt/local/lib/ruby/1.8/set.rb"
|
10
|
+
|
11
|
+
.. Load a bunch of gems with spec directories ..
|
12
|
+
|
13
|
+
> $LOAD_PATH.find_all_files('../spec')
|
14
|
+
|
15
|
+
And you'll get an array of matches.
|
16
|
+
|
17
|
+
> $LOAD_PATH.find_all_files('../spec') {|file| puts "here is a spec! #{file}"}
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "load_path_find"
|
7
|
+
s.description = s.summary = "Convenient way to find stuff on the load path."
|
8
|
+
s.email = "joshbuddy@gmail.com"
|
9
|
+
s.homepage = "http://github.com/joshbuddy/load_path_find"
|
10
|
+
s.authors = "Joshua Hull"
|
11
|
+
s.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"]
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'spec'
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
task :spec => 'spec:all'
|
21
|
+
namespace(:spec) do
|
22
|
+
Spec::Rake::SpecTask.new(:all) do |t|
|
23
|
+
t.spec_opts ||= []
|
24
|
+
t.spec_opts << "-rubygems"
|
25
|
+
t.spec_opts << "--options" << "spec/spec.opts"
|
26
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.instance_eval do
|
2
|
+
def find_file(file)
|
3
|
+
find_all_files(file){|f| return f}
|
4
|
+
nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_all_files(file)
|
8
|
+
inject([]){|ary, path|
|
9
|
+
target = File.join(path, file)
|
10
|
+
if File.readable?(target)
|
11
|
+
ary << target
|
12
|
+
yield target if block_given?
|
13
|
+
end
|
14
|
+
ary
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'lib/load_path_find'
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), 'data', 'dir1'))
|
4
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), 'data', 'dir2'))
|
5
|
+
|
6
|
+
describe 'load path find' do
|
7
|
+
it "should find a file on the load path" do
|
8
|
+
target = File.join('file1')
|
9
|
+
$:.find_file(target)[-target.size, target.size].should == target
|
10
|
+
end
|
11
|
+
|
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
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should find the first file when its ambigious" do
|
18
|
+
target = File.join('file1')
|
19
|
+
expected_target = File.join('dir1', 'file1')
|
20
|
+
$:.find_file(target)[-expected_target.size, expected_target.size].should == expected_target
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should find all files that match" do
|
24
|
+
target = File.join('file1')
|
25
|
+
expected_target = File.join('dir1', 'file1')
|
26
|
+
$:.find_all_files(target).should == [
|
27
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'data', 'dir1', 'file1')),
|
28
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'data', 'dir2', 'file1'))
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should yield all files that match if a block is given" do
|
33
|
+
target = File.join('file1')
|
34
|
+
mock = Object.new
|
35
|
+
mock.should_receive(:hello).exactly(2).times
|
36
|
+
$:.find_all_files(target) { mock.hello }
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec.opts
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: load_path_find
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Hull
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-16 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Convenient way to find stuff on the load path.
|
17
|
+
email: joshbuddy@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- lib/load_path_find.rb
|
29
|
+
- spec/data/dir1/file1
|
30
|
+
- spec/data/dir2/file1
|
31
|
+
- spec/load_path_find_spec.rb
|
32
|
+
- spec/spec.opts
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/joshbuddy/load_path_find
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --charset=UTF-8
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Convenient way to find stuff on the load path.
|
61
|
+
test_files:
|
62
|
+
- spec/load_path_find_spec.rb
|