ruby-which 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENCE +21 -0
  2. data/README +26 -0
  3. data/bin/rwhich +30 -0
  4. data/lib/ruby-which.rb +45 -0
  5. metadata +57 -0
data/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT Licence
2
+
3
+ Copyright (c) 2009 Pistos
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,26 @@
1
+ = ruby-which
2
+
3
+ by Pistos
4
+ http://github.com/Pistos/ruby-which
5
+
6
+ For those times when you don't know which version of a library you're
7
+ require-ing, or what path on your system it's coming from. Returns the full
8
+ library path if the given library is found in the $LOAD_PATH.
9
+
10
+ "you need organization..." -- manveru
11
+
12
+ == Installation
13
+
14
+ gem install --source http://gems.github.com Pistos-ruby-which
15
+
16
+ == Example usage:
17
+
18
+ require 'rubygems'
19
+ require 'ruby-which'
20
+ puts Which.which( 'm4dbi' ) #=> /usr/lib/ruby/gems/1.8/gems/m4dbi-0.6.2/lib/m4dbi.rb
21
+
22
+ Or from your shell:
23
+
24
+ rwhich m4dbi
25
+ # Outputs: /usr/lib/ruby/gems/1.8/gems/m4dbi-0.6.2/lib/m4dbi.rb
26
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'ruby-which'
5
+
6
+ libs = []
7
+ verbose = false
8
+
9
+ argv = ARGV.dup
10
+ while argv.length > 0
11
+ arg = argv.shift
12
+ case arg
13
+ when '-v', '--verbose'
14
+ verbose = true
15
+ else
16
+ libs << arg
17
+ end
18
+ end
19
+
20
+ libs.each do |lib|
21
+ if verbose
22
+ print "#{lib}: "
23
+ end
24
+ found = Which.which( arg )
25
+ if found
26
+ puts found
27
+ else
28
+ puts "(not found)"
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ # ruby-which
2
+
3
+ # For those times when you don't know which version of a library you're require-ing,
4
+ # or from what path on your system it's coming from.
5
+
6
+ # by Pistos
7
+ # http://github.com/Pistos/ruby-which
8
+
9
+ # <manveru> you need organization...
10
+
11
+ class Which
12
+ # Example usage:
13
+ # puts Which.which( 'rails' )
14
+ # Or from your shell:
15
+ # rwhich rails
16
+ # Returns the full library path if the given library is found in the $LOAD_PATH.
17
+ # Under rare circumstances, an Array may be returned in the case of multiple
18
+ # matches under one path.
19
+ def self.which( lib )
20
+ begin
21
+ Kernel#require( lib )
22
+ rescue LoadError
23
+ return nil
24
+ end
25
+
26
+ $LOAD_PATH.each do |path|
27
+ extension = nil
28
+ if File.extname( lib ).empty?
29
+ extension = '.{rb,so,o,dll,class}'
30
+ end
31
+ found = Dir[ "#{path}/#{lib}#{extension}" ]
32
+ if found.size == 1
33
+ return found[ 0 ]
34
+ elsif found.any?
35
+ return found
36
+ end
37
+ end
38
+
39
+ nil
40
+ end
41
+
42
+ class << self
43
+ alias_method :require, :which
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-which
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Pistos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-26 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Use ruby-which for those times when you don't know which version of a library you're require-ing, or from what path on your system it's coming from.
17
+ email: pistos at purepistos dot net
18
+ executables:
19
+ - rwhich
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - LICENCE
25
+ files:
26
+ - README
27
+ - LICENCE
28
+ - bin/rwhich
29
+ - lib/ruby-which.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/Pistos/ruby-which
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.1
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Like the UNIX "which" tool for Ruby libraries.
56
+ test_files: []
57
+