open_gem 1.2.0
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.markdown +28 -0
- data/Rakefile +34 -0
- data/VERSION.yml +4 -0
- data/lib/rubygems/commands/open_command.rb +73 -0
- data/lib/rubygems_plugin.rb +3 -0
- data/test/open_command_test.rb +41 -0
- metadata +69 -0
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
OpenGem
|
2
|
+
========
|
3
|
+
|
4
|
+
Simply opens the specified gem in your default editor.
|
5
|
+
|
6
|
+
gem open rails
|
7
|
+
|
8
|
+
Installation:
|
9
|
+
------------
|
10
|
+
OpenGem require rubygems 1.3.2 or higher. You may need
|
11
|
+
to update rubygems to take advantage of the new plugin support:
|
12
|
+
|
13
|
+
gem update --system
|
14
|
+
|
15
|
+
Just install like any normal gem:
|
16
|
+
|
17
|
+
gem install open_gem
|
18
|
+
|
19
|
+
Or for the edge version on GitHub:
|
20
|
+
|
21
|
+
gem sources -a http://gems.github.com
|
22
|
+
gem install adamsanderson-open_gem
|
23
|
+
|
24
|
+
For more help:
|
25
|
+
|
26
|
+
gem open --help
|
27
|
+
|
28
|
+
Adam Sanderson, netghost@gmail.com
|
data/Rakefile
ADDED
@@ -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 = "open_gem"
|
9
|
+
s.summary = "Gem Command to easily open a ruby gem with the editor of your choice."
|
10
|
+
s.description = <<-DESC
|
11
|
+
Open a gem's source directory with either the default editor, or a specified command.
|
12
|
+
DESC
|
13
|
+
s.email = "netghost@gmail.com"
|
14
|
+
s.homepage = "http://github.com/adamsanderson/open_gem"
|
15
|
+
s.authors = ["Adam Sanderson"]
|
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
|
data/VERSION.yml
ADDED
@@ -0,0 +1,73 @@
|
|
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::OpenCommand < Gem::Command
|
9
|
+
include Gem::VersionOption
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super 'open', "Opens the gem's source directory with $GEM_OPEN_EDITOR or $EDITOR",
|
13
|
+
:command => nil,
|
14
|
+
:version=> Gem::Requirement.default,
|
15
|
+
:latest=> false
|
16
|
+
|
17
|
+
add_option('-c', '--command COMMAND',
|
18
|
+
'Execute command at path of the rubygem') do |value, options|
|
19
|
+
options[:command] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
add_option('-l', '--latest',
|
23
|
+
'If there are multiple versions, open the latest') do |value, options|
|
24
|
+
options[:latest] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
add_version_option
|
28
|
+
end
|
29
|
+
|
30
|
+
def arguments # :nodoc:
|
31
|
+
"GEMNAME gem to open"
|
32
|
+
end
|
33
|
+
|
34
|
+
def execute
|
35
|
+
name = get_one_gem_name
|
36
|
+
path = get_path(name)
|
37
|
+
|
38
|
+
open_gem(path) if path
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_path(name)
|
42
|
+
dep = Gem::Dependency.new name, options[:version]
|
43
|
+
specs = Gem.source_index.search dep
|
44
|
+
|
45
|
+
if specs.length == 0
|
46
|
+
say "Could not find '#{name}'"
|
47
|
+
return nil
|
48
|
+
|
49
|
+
elsif specs.length == 1 || options[:latest]
|
50
|
+
return specs.last.full_gem_path
|
51
|
+
|
52
|
+
else
|
53
|
+
choices = specs.map{|s|"#{s.name} #{s.version}"}
|
54
|
+
c,i = choose_from_list "Open which gem?", choices
|
55
|
+
return specs[i].full_gem_path if i
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def open_gem(path)
|
61
|
+
editor = options[:command] || ENV['GEM_OPEN_EDITOR'] || ENV['EDITOR']
|
62
|
+
if !editor
|
63
|
+
say "Either set $EDITOR, or use -c <command_name>"
|
64
|
+
else
|
65
|
+
command_parts = Shellwords.shellwords(editor)
|
66
|
+
command_parts << path
|
67
|
+
success = system(*command_parts)
|
68
|
+
if !success
|
69
|
+
raise Gem::CommandLineError, "Could not run '#{editor} #{path}', exit code: #{$?.exitstatus}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'mocha'
|
4
|
+
|
5
|
+
require 'rubygems/commands/open_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::OpenCommand.new
|
16
|
+
|
17
|
+
command.expects(:get_path).with(gem_name).returns(gem_path)
|
18
|
+
command.expects(:open_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::OpenCommand.new
|
27
|
+
|
28
|
+
command.expects(:get_path).with(gem_name).returns(gem_path)
|
29
|
+
command.expects(:open_gem).never
|
30
|
+
|
31
|
+
command.invoke(gem_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_opening_with_no_gem_name
|
35
|
+
command = Gem::Commands::OpenCommand.new
|
36
|
+
|
37
|
+
assert_raises Gem::CommandLineError do
|
38
|
+
command.invoke()
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: open_gem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Sanderson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-02 00:00:00 -07: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: " Open a gem's source directory with either the default editor, or a specified command.\n"
|
26
|
+
email: netghost@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.markdown
|
33
|
+
files:
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- VERSION.yml
|
37
|
+
- lib/rubygems/commands/open_command.rb
|
38
|
+
- lib/rubygems_plugin.rb
|
39
|
+
- test/open_command_test.rb
|
40
|
+
has_rdoc: false
|
41
|
+
homepage: http://github.com/adamsanderson/open_gem
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
requirements: []
|
62
|
+
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Gem Command to easily open a ruby gem with the editor of your choice.
|
68
|
+
test_files:
|
69
|
+
- test/open_command_test.rb
|