rwhich 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ce247c822f4c9d8c673717f5ac88fd6b61eb8f9
4
+ data.tar.gz: 4998bacdfecce337268d9abb95c22a3dc4a2019c
5
+ SHA512:
6
+ metadata.gz: bc015977c7b5fcea59f2fbf026aad859dfd8897f891667b06b880f38e67da1a5fc54d4f19076cd03b58dc67b205d2d729f5aefe762b4c68fd777397507515f71
7
+ data.tar.gz: 654f43b20272217fea527e470eb2dd290d324fb20d3213acfd9688f99f89537837c2984de8f9e82d8de097e428a0e76f1b52e1e0bf0b592fc8b40147d9b318e2
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ "Software"), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,22 @@
1
+ Based on tenderlove's #which http://tenderlovemaking.com/2011/12/05/profiling-rails-startup-with-dtrace/
2
+
3
+ Base Use:
4
+ > require 'rwhich/file'
5
+ > File.which 'ls'
6
+ => "/bin/ls"
7
+ > File.which 'hahahahahah' #assuming you don't have a hahahahahah executable in ENV['PATH']
8
+ => nil
9
+
10
+ Other Use:
11
+ > require 'rwhich'
12
+ > Class Foo
13
+ extend RWhich
14
+ end
15
+ > Foo.which 'ls'
16
+ => "/bin/ls"
17
+ > Class Bar
18
+ include RWhich
19
+ end
20
+ > bar = Bar.new
21
+ > bar.which 'ls'
22
+ => "/bin/ls"
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'rake/testtask'
15
+ Rake::TestTask.new(:test) do |test|
16
+ test.libs << 'lib' << 'test'
17
+ test.pattern = 'test/**/test_*.rb'
18
+ test.verbose = true
19
+ end
20
+
21
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ # Provides a mixin that add's #which
2
+ module RWhich
3
+
4
+ # returns the first executable match of filename in the path
5
+ #
6
+ # @note Only supports the base use case of the which command line program
7
+ #
8
+ # @param [String] filename the filename to find
9
+ # @param [String] path the path to search, defaults to ENV['PATH']
10
+ # @param [String] path_sep the path separator, defaults to File::PATH_SEPARATOR
11
+ def which filename, path=ENV['PATH'], path_sep=File::PATH_SEPARATOR
12
+ path = path.split(path_sep).find { |path| File.executable? File.join(path, filename) }
13
+ path && File.expand_path(filename, path)
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ require_relative '../rwhich'
2
+
3
+ # Mixin .which into File
4
+ class File
5
+ extend RWhich
6
+ end
@@ -0,0 +1,37 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rwhich"
3
+ s.version = "0.0.1"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+
7
+ s.authors = ["Edward Muller"]
8
+ s.date = "2011-12-09"
9
+ s.description = "Ruby Which"
10
+ s.email = "edwardam@interlix.com"
11
+
12
+ s.extra_rdoc_files = [
13
+ "LICENSE.txt",
14
+ "README"
15
+ ]
16
+
17
+ s.files = [
18
+ "Gemfile",
19
+ "Rakefile",
20
+ "rwhich.gemspec",
21
+ "lib/rwhich.rb",
22
+ "lib/rwhich/file.rb",
23
+ "test/helper.rb",
24
+ "test/test_rwhich.rb"
25
+ ]
26
+
27
+ s.homepage = "http://github.com/freeformz/rwhich"
28
+ s.licenses = ["MIT"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = "1.8.10"
31
+ s.summary = "Ruby Which"
32
+
33
+ s.specification_version = 3
34
+ s.add_development_dependency 'minitest', '~> 5.7'
35
+ s.add_development_dependency 'bundler', '~> 1.7'
36
+ s.add_development_dependency 'rake', '~> 10'
37
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+ require 'minitest/spec'
12
+
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ require 'rwhich'
16
+ require 'rwhich/file'
17
+
18
+ class MiniTest::Unit::TestCase
19
+ end
20
+
21
+ MiniTest::Unit.autorun
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class Witch
4
+ include RWhich
5
+ extend RWhich
6
+ end
7
+
8
+ describe "when extended by RWhich" do
9
+ subject { Witch }
10
+
11
+ it "should find a common utility" do
12
+ Witch.which('ls').wont_be_nil
13
+ end
14
+
15
+ it "should not find something that doesn't exist" do
16
+ Witch.which('afdbn4tnewgq3nq4tnw4ymqt4nw4tnwrntn').must_be_nil
17
+ end
18
+ end
19
+
20
+ describe "when RWhich is included in" do
21
+ subject { Witch.new }
22
+
23
+ it "should find a common utility" do
24
+ subject.which('ls').wont_be_nil
25
+ end
26
+
27
+ it "should not find something that doesn't exist" do
28
+ subject.which('afdbn4tnewgq3nq4tnw4ymqt4nw4tnwrntn').must_be_nil
29
+ end
30
+ end
31
+
32
+ describe File do
33
+ it "should respond to which" do
34
+ File.must_respond_to :which
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rwhich
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Edward Muller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2011-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ description: Ruby Which
56
+ email: edwardam@interlix.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files:
60
+ - LICENSE.txt
61
+ - README
62
+ files:
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README
66
+ - Rakefile
67
+ - lib/rwhich.rb
68
+ - lib/rwhich/file.rb
69
+ - rwhich.gemspec
70
+ - test/helper.rb
71
+ - test/test_rwhich.rb
72
+ homepage: http://github.com/freeformz/rwhich
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.8
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Ruby Which
96
+ test_files: []