adamsanderson-open_gem 1.0.0 → 1.1.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 +9 -1
- data/Rakefile +5 -1
- data/VERSION.yml +1 -1
- data/lib/rubygems/commands/open_command.rb +12 -9
- data/test/open_command_test.rb +42 -0
- metadata +16 -6
data/README.markdown
CHANGED
@@ -5,8 +5,16 @@ Simply opens the specified gem in your default editor.
|
|
5
5
|
|
6
6
|
gem open rails
|
7
7
|
|
8
|
+
Installation:
|
9
|
+
------------
|
10
|
+
|
11
|
+
Just install like any normal gem:
|
12
|
+
gem install adamsanderson-open_gem
|
13
|
+
|
14
|
+
You might need to add Github as a gem source:
|
15
|
+
gem sources -a http://gems.github.com
|
16
|
+
|
8
17
|
For more help:
|
9
18
|
gem open --help
|
10
19
|
|
11
|
-
|
12
20
|
Adam Sanderson, netghost@gmail.com
|
data/Rakefile
CHANGED
@@ -15,6 +15,10 @@ begin
|
|
15
15
|
s.authors = ["Adam Sanderson"]
|
16
16
|
s.has_rdoc = false
|
17
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'
|
18
22
|
end
|
19
23
|
|
20
24
|
rescue LoadError
|
@@ -27,4 +31,4 @@ Rake::TestTask.new do |t|
|
|
27
31
|
t.verbose = false
|
28
32
|
end
|
29
33
|
|
30
|
-
task :default => :
|
34
|
+
task :default => :test
|
data/VERSION.yml
CHANGED
@@ -7,7 +7,7 @@ class Gem::Commands::OpenCommand < Gem::Command
|
|
7
7
|
include Gem::VersionOption
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
super 'open', "Opens the gem's source directory with $EDITOR",
|
10
|
+
super 'open', "Opens the gem's source directory with $GEM_OPEN_EDITOR or $EDITOR",
|
11
11
|
:command => nil,
|
12
12
|
:version=> Gem::Requirement.default,
|
13
13
|
:latest=> false
|
@@ -29,31 +29,34 @@ class Gem::Commands::OpenCommand < Gem::Command
|
|
29
29
|
"GEMNAME gem to open"
|
30
30
|
end
|
31
31
|
|
32
|
-
def execute
|
32
|
+
def execute
|
33
33
|
name = get_one_gem_name
|
34
|
+
path = get_path(name)
|
34
35
|
|
36
|
+
open_gem(path) if path
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_path(name)
|
35
40
|
dep = Gem::Dependency.new name, options[:version]
|
36
41
|
specs = Gem.source_index.search dep
|
37
42
|
|
38
43
|
if specs.length == 0
|
39
44
|
say "Could not find '#{name}'"
|
45
|
+
return nil
|
40
46
|
|
41
47
|
elsif specs.length == 1 || options[:latest]
|
42
|
-
|
48
|
+
return specs.last.full_gem_path
|
43
49
|
|
44
50
|
else
|
45
51
|
choices = specs.map{|s|"#{s.name} #{s.version}"}
|
46
52
|
c,i = choose_from_list "Open which gem?", choices
|
47
|
-
|
53
|
+
return specs[i].full_gem_path if i
|
48
54
|
|
49
55
|
end
|
50
|
-
|
51
|
-
open_gem(path) if path
|
52
56
|
end
|
53
|
-
|
54
|
-
private
|
57
|
+
|
55
58
|
def open_gem(path)
|
56
|
-
editor = options[:command] || ENV['EDITOR']
|
59
|
+
editor = options[:command] || ENV['GEM_OPEN_EDITOR'] || ENV['EDITOR']
|
57
60
|
if !editor
|
58
61
|
say "Either set $EDITOR, or use -c <command_name>"
|
59
62
|
else
|
@@ -0,0 +1,42 @@
|
|
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
|
+
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adamsanderson-open_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Sanderson
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
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:
|
16
25
|
description: Open a gem's source directory with either the default editor, or a specified command.
|
17
26
|
email: netghost@gmail.com
|
18
27
|
executables: []
|
@@ -27,6 +36,7 @@ files:
|
|
27
36
|
- VERSION.yml
|
28
37
|
- lib/rubygems/commands/open_command.rb
|
29
38
|
- lib/rubygems_plugin.rb
|
39
|
+
- test/open_command_test.rb
|
30
40
|
has_rdoc: false
|
31
41
|
homepage: http://github.com/adamsanderson/open_gem
|
32
42
|
post_install_message:
|
@@ -53,5 +63,5 @@ rubygems_version: 1.2.0
|
|
53
63
|
signing_key:
|
54
64
|
specification_version: 3
|
55
65
|
summary: Gem Command to easily open a ruby gem with the editor of your choice.
|
56
|
-
test_files:
|
57
|
-
|
66
|
+
test_files:
|
67
|
+
- test/open_command_test.rb
|