gem_dir 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ Gem Dir
2
+ ========
3
+
4
+ Prints the root directory of the specified gem.
5
+
6
+ gem dir rails
7
+
8
+ Installation:
9
+ ------------
10
+
11
+ Just install like any normal gem:
12
+ gem install mperham-gem_dir
13
+
14
+ You might need to add Github as a gem source:
15
+ gem sources -a http://gems.github.com
16
+
17
+ For more help:
18
+ gem dir --help
19
+
20
+
21
+ Thanks
22
+ -------------
23
+
24
+ Based on Adam Sanderson's open_gem.
@@ -0,0 +1,34 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "gem_dir"
9
+ s.summary = "Gem Command to easily locate a ruby gem."
10
+ s.description = <<-DESC
11
+ Prints the install directory for the selected gem.
12
+ DESC
13
+ s.email = "mperham@gmail.com"
14
+ s.homepage = "http://github.com/mperham/gem_dir"
15
+ s.authors = ["Mike Perham"]
16
+ s.has_rdoc = false
17
+ s.files = FileList["[A-Z]*", "{bin,lib,test}/**/*"]
18
+
19
+ # Testing
20
+ s.test_files = FileList["test/**/*_test.rb"]
21
+ s.add_development_dependency 'mocha', '~> 0.9.5'
22
+ end
23
+
24
+ rescue LoadError
25
+ puts "Jeweler not available. Install it for jeweler-related tasks with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
26
+ end
27
+
28
+ Rake::TestTask.new do |t|
29
+ t.libs << 'lib'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ ---
2
+ :patch: 0
3
+ :major: 1
4
+ :minor: 0
@@ -0,0 +1,58 @@
1
+ require 'shellwords'
2
+
3
+ require 'rubygems/command'
4
+ require 'rubygems/dependency'
5
+ require 'rubygems/version_option'
6
+
7
+ # OpenCommand will open a gem's source path
8
+ class Gem::Commands::DirCommand < Gem::Command
9
+ include Gem::VersionOption
10
+
11
+ def initialize
12
+ super 'dir', "Prints the install directory of the selected gem",
13
+ :command => nil,
14
+ :version=> Gem::Requirement.default,
15
+ :latest=> false
16
+
17
+ add_option('-l', '--latest',
18
+ 'If there are multiple versions, open the latest') do |value, options|
19
+ options[:latest] = true
20
+ end
21
+
22
+ add_version_option
23
+ end
24
+
25
+ def arguments # :nodoc:
26
+ "GEMNAME gem to use"
27
+ end
28
+
29
+ def execute
30
+ name = get_one_gem_name
31
+ path = get_path(name)
32
+
33
+ dir_gem(path) if path
34
+ end
35
+
36
+ def get_path(name)
37
+ dep = Gem::Dependency.new name, options[:version]
38
+ specs = Gem.source_index.search dep
39
+
40
+ if specs.length == 0
41
+ say "Could not find '#{name}'"
42
+ return nil
43
+
44
+ elsif specs.length == 1 || options[:latest]
45
+ return specs.last.full_gem_path
46
+
47
+ else
48
+ choices = specs.map{|s|"#{s.name} #{s.version}"}
49
+ c,i = choose_from_list "Use which gem?", choices
50
+ return specs[i].full_gem_path if i
51
+
52
+ end
53
+ end
54
+
55
+ def dir_gem(path)
56
+ puts path
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems/command_manager'
2
+
3
+ Gem::CommandManager.instance.register_command :dir
@@ -0,0 +1,41 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+
5
+ require 'rubygems/commands/dir_command'
6
+ require 'rubygems/exceptions'
7
+
8
+ class Test_SomethingToTest < Test::Unit::TestCase
9
+ def setup
10
+ end
11
+
12
+ def test_opening_path
13
+ gem_name = 'neat_gem'
14
+ gem_path = 'some/path'
15
+ command = Gem::Commands::DirCommand.new
16
+
17
+ command.expects(:get_path).with(gem_name).returns(gem_path)
18
+ command.expects(:dir_gem).with(gem_path)
19
+
20
+ command.invoke(gem_name)
21
+ end
22
+
23
+ def test_opening_nonexistent_path
24
+ gem_name = 'neat_gem'
25
+ gem_path = nil
26
+ command = Gem::Commands::DirCommand.new
27
+
28
+ command.expects(:get_path).with(gem_name).returns(gem_path)
29
+ command.expects(:dir_gem).never
30
+
31
+ command.invoke(gem_name)
32
+ end
33
+
34
+ def test_opening_with_no_gem_name
35
+ command = Gem::Commands::DirCommand.new
36
+
37
+ assert_raises Gem::CommandLineError do
38
+ command.invoke()
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_dir
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mike Perham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-28 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mocha
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.5
24
+ version:
25
+ description: " Prints the install directory for the selected gem.\n"
26
+ email: mperham@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.markdown
33
+ files:
34
+ - Rakefile
35
+ - README.markdown
36
+ - VERSION.yml
37
+ - lib/rubygems/commands/dir_command.rb
38
+ - lib/rubygems_plugin.rb
39
+ - test/dir_command_test.rb
40
+ has_rdoc: true
41
+ homepage: http://github.com/mperham/gem_dir
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --inline-source
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Gem Command to easily locate a ruby gem.
69
+ test_files:
70
+ - test/dir_command_test.rb