mypath 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ mypath
2
+ ======
3
+
4
+ mypath takes a path and prints the corresponding local path. Works for gems and for paths corresponding to your current working directory.
5
+
6
+ Examples
7
+ --------
8
+
9
+ $ mypath "[GEM_ROOT]/gems/resque-1.10.0/lib/resque/worker.rb:157:in `perform'"
10
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/resque-1.10.0/lib/resque/worker.rb
11
+
12
+ # In the next case, the following was in the osx clipboard:
13
+ # lib/synchronizable_model.rb:51:in `perform'
14
+ # lib/synchronizable_model.rb:70:in `replicate'
15
+ # lib/synchronizable_model.rb:22:in `remote_update'
16
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:178:in `send'
17
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:178:in `evaluate_method'
18
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:166:in `call'
19
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:93:in `run'
20
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:92:in `each'
21
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:92:in `send'
22
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:92:in `run'
23
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:276:in `run_callbacks
24
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/callbacks.rb:344:in `callback'
25
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/callbacks.rb:251:in `create_or_update'
26
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/base.rb:2577:in `save_without_validation'
27
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/validations.rb:1090:in `save_without_dirty'
28
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/dirty.rb:79:in `save_without_transactions'
29
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:229:in `send'
30
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
31
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
32
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:182:in `transaction'
33
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
34
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:196:in `save'
35
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
36
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/transactions.rb:196:in `save'
37
+ # [GEM_ROOT]/gems/activerecord-2.3.10/lib/active_record/base.rb:2661:in `update_attribute'
38
+ # app/models/user_session.rb:53:in `reset_record_last_request_at'
39
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:178:in `send'
40
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:178:in `evaluate_method'
41
+ # [GEM_ROOT]/gems/activesupport-2.3.10/lib/active_support/callbacks.rb:166:in `call'
42
+
43
+ $ pbpaste | mypath
44
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activesupport-2.3.10/lib/active_support/callbacks.rb
45
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/callbacks.rb
46
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/base.rb
47
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/validations.rb
48
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/dirty.rb
49
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/transactions.rb
50
+ /Users/daniel/.rvm/gems/ree-1.8.7-2010.02/gems/activerecord-2.3.10/lib/active_record/connection_adapters/abstract/database_statements.rb
51
+
52
+
53
+ Contributing to mypath
54
+ ----------------------
55
+
56
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
57
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
58
+ * Fork the project
59
+ * Start a feature/bugfix branch
60
+ * Commit and push until you are happy with your contribution
61
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
62
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
63
+
64
+ Copyright
65
+ ---------
66
+
67
+ Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
68
+ further details.
69
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/bin/mypath CHANGED
@@ -8,4 +8,4 @@ paths = stdin || ARGV[0]
8
8
  paths = paths.split("\n")
9
9
 
10
10
  output = paths.collect{ |p| MyPath.local_path_for(p) }.select{ |p| !(p.nil? || p.empty?)}.uniq.join("\n")
11
- puts output if output
11
+ puts output if output && !output.empty?
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+
1
3
  module MyPath
2
4
  require 'mypath/handler'
3
5
  require 'mypath/handler/gem'
@@ -5,14 +5,15 @@ module MyPath
5
5
  clean_path(path) =~ /\/gems\//
6
6
  end
7
7
 
8
- def local_path
9
- gem_path = /.*?\/gems\/.*?([^\/]+?-\d\..*)/.match(self.path)[1]
10
- if ENV['GEM_HOME']
11
- File.join(ENV['GEM_HOME'], 'gems', gem_path)
12
- else
13
- end
8
+ def self.local_gem_paths
9
+ @local_gem_paths ||= ::Gem.path.collect{ |g| File.join(g, 'gems') }
14
10
  end
15
11
 
12
+ def local_path
13
+ remote_gem_path = /.*?\/gems\/.*?([^\/]+?-\d\..*)/.match(self.path)[1]
14
+ joined = self.class.local_gem_paths.collect{|g| File.join(g, remote_gem_path)}
15
+ Dir[*joined].first
16
+ end
16
17
  end
17
18
  end
18
19
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mypath}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Daniel Higginbotham"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.executables = ["mypath", "mypath"]
16
16
  s.extra_rdoc_files = [
17
17
  "LICENSE.txt",
18
- "README.rdoc"
18
+ "README.md"
19
19
  ]
20
20
  s.files = [
21
21
  ".document",
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  "Gemfile",
24
24
  "Gemfile.lock",
25
25
  "LICENSE.txt",
26
- "README.rdoc",
26
+ "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "bin/mypath",
@@ -20,12 +20,14 @@ describe MyPath::Handler::Gem do
20
20
 
21
21
  describe "#local_path" do
22
22
  it "returns a path relative to your local GEM_HOME environment variable" do
23
- old_gem_home = ENV['GEM_HOME']
24
- ENV['GEM_HOME'] = gem_home
25
-
23
+ handler.class.stub(:local_gem_paths).and_return([File.join(gem_home, "gems")])
26
24
  handler.local_path.should == local_dummy_gem_path
27
-
28
- ENV['GEM_HOME'] = old_gem_home
25
+ end
26
+ end
27
+
28
+ describe "#local_gem_paths" do
29
+ it "ends in 'gems'" do
30
+ handler.class.local_gem_paths.each{ |g| g.should =~ /gems$/ }
29
31
  end
30
32
  end
31
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mypath
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Higginbotham
@@ -117,14 +117,14 @@ extensions: []
117
117
 
118
118
  extra_rdoc_files:
119
119
  - LICENSE.txt
120
- - README.rdoc
120
+ - README.md
121
121
  files:
122
122
  - .document
123
123
  - .rspec
124
124
  - Gemfile
125
125
  - Gemfile.lock
126
126
  - LICENSE.txt
127
- - README.rdoc
127
+ - README.md
128
128
  - Rakefile
129
129
  - VERSION
130
130
  - bin/mypath
@@ -1,19 +0,0 @@
1
- = mypath
2
-
3
- Description goes here.
4
-
5
- == Contributing to mypath
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
- * Fork the project
10
- * Start a feature/bugfix branch
11
- * Commit and push until you are happy with your contribution
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2011 Daniel Higginbotham. See LICENSE.txt for
18
- further details.
19
-