gem-open 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +62 -0
- data/Rakefile +21 -0
- data/lib/rubygems/commands/open.rb +67 -0
- data/lib/rubygems_plugin.rb +5 -0
- data/test/gem_open_test.rb +69 -0
- metadata +65 -0
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= GemOpen
|
2
|
+
|
3
|
+
Open gems into your favorite editor by running a specific gem command.
|
4
|
+
|
5
|
+
To install it just run
|
6
|
+
|
7
|
+
sudo gem install gem-open
|
8
|
+
|
9
|
+
Then add the following lines to your <tt>~/.bash_profile</tt> file.
|
10
|
+
|
11
|
+
export GEM_EDITOR="mate"
|
12
|
+
|
13
|
+
Finally, run <tt>gem open GEMNAME</tt> to open that gem.
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
To open the most recent version you just need to type the gem name.
|
18
|
+
|
19
|
+
$ gem open activesupport
|
20
|
+
|
21
|
+
If you want to open a specific version you'll have to type the full name.
|
22
|
+
|
23
|
+
$ gem open activesupport-3.0.0.beta3
|
24
|
+
|
25
|
+
== Bash completion
|
26
|
+
|
27
|
+
Want some completion? Add this snippet to your <tt>~/.bash_profile</tt> file.
|
28
|
+
|
29
|
+
_gemopencomplete() {
|
30
|
+
local cmd=${COMP_WORDS[0]}
|
31
|
+
local subcmd=${COMP_WORDS[1]}
|
32
|
+
local cur=${COMP_WORDS[COMP_CWORD]}
|
33
|
+
|
34
|
+
case "$subcmd" in
|
35
|
+
open)
|
36
|
+
words=`ruby -rubygems -e 'puts Dir["{#{Gem::SourceIndex.installed_spec_directories.join(",")}}/*.gemspec"].collect {|s| File.basename(s).gsub(/\.gemspec$/, "")}'`
|
37
|
+
;;
|
38
|
+
*)
|
39
|
+
return
|
40
|
+
;;
|
41
|
+
esac
|
42
|
+
|
43
|
+
COMPREPLY=($(compgen -W "$words" -- $cur))
|
44
|
+
return 0
|
45
|
+
}
|
46
|
+
|
47
|
+
complete -o default -F _gemopencomplete gem
|
48
|
+
|
49
|
+
== License
|
50
|
+
|
51
|
+
(The MIT License)
|
52
|
+
|
53
|
+
Copyright © 2010:
|
54
|
+
|
55
|
+
* Nando Vieira - http://simplesideias.com.br
|
56
|
+
|
57
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
58
|
+
|
59
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
62
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rake/testtask"
|
2
|
+
require "jeweler"
|
3
|
+
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
Jeweler::Tasks.new do |gem|
|
12
|
+
gem.name = "gem-open"
|
13
|
+
gem.version = "0.1.0"
|
14
|
+
gem.summary = "Open gems into your favorite editor by running a specific gem command."
|
15
|
+
gem.email = "fnando.vieira@gmail.com"
|
16
|
+
gem.homepage = "http://github.com/fnando/open-gem"
|
17
|
+
gem.authors = ["Nando Vieira"]
|
18
|
+
gem.files = FileList["lib/**/*", "Rakefile", "README.rdoc"]
|
19
|
+
end
|
20
|
+
|
21
|
+
Jeweler::GemcutterTasks.new
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class Gem::Commands::OpenCommand < Gem::Command
|
2
|
+
def description
|
3
|
+
"Open a gem into your favorite editor"
|
4
|
+
end
|
5
|
+
|
6
|
+
def arguments
|
7
|
+
"GEM gem's name"
|
8
|
+
end
|
9
|
+
|
10
|
+
def usage
|
11
|
+
"#{program_name} GEM"
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super "open", description
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
gemname = options[:args].first
|
20
|
+
|
21
|
+
unless gemname
|
22
|
+
say "Usage: #{usage}"
|
23
|
+
return terminate_interaction
|
24
|
+
end
|
25
|
+
|
26
|
+
spec = search(gemname)
|
27
|
+
|
28
|
+
if spec
|
29
|
+
open(spec)
|
30
|
+
else
|
31
|
+
say "The #{gemname.inspect} gem couldn't be found"
|
32
|
+
return terminate_interaction
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def search(gemname)
|
37
|
+
regex = /^(.*?)(?:-(.*?))?$/
|
38
|
+
_, required_name, required_version = *gemname.match(regex)
|
39
|
+
|
40
|
+
gemspecs = Dir["{#{Gem::SourceIndex.installed_spec_directories.join(",")}}/*.gemspec"].select do |gemspec|
|
41
|
+
basename = File.basename(gemspec).gsub(/\.gemspec$/, "")
|
42
|
+
_, name, version = *basename.match(regex)
|
43
|
+
|
44
|
+
if required_version
|
45
|
+
basename == gemname
|
46
|
+
else
|
47
|
+
name == gemname
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
gemspec = gemspecs.sort.last
|
52
|
+
|
53
|
+
return unless gemspec
|
54
|
+
|
55
|
+
Gem::SourceIndex.load_specification(gemspec)
|
56
|
+
end
|
57
|
+
|
58
|
+
def open(spec)
|
59
|
+
if ENV["GEM_EDITOR"]
|
60
|
+
system "#{ENV["GEM_EDITOR"]} #{spec.full_gem_path}"
|
61
|
+
else
|
62
|
+
say "You must set your editor in your .bash_profile or equivalent:"
|
63
|
+
say " export GEM_EDITOR='mate'"
|
64
|
+
return terminate_interaction
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
gem "test-unit"
|
3
|
+
require "test/unit"
|
4
|
+
require "mocha"
|
5
|
+
require "rubygems_plugin"
|
6
|
+
require "FileUtils"
|
7
|
+
|
8
|
+
class GemOpenTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
ENV["GEM_EDIT"] = "mate"
|
11
|
+
@plugin = Gem::Commands::OpenCommand.new
|
12
|
+
@gemdir = File.expand_path(File.dirname(__FILE__) + "/gems")
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_require_gem_name_to_be_set
|
16
|
+
@plugin.expects(:options).returns(:args => [])
|
17
|
+
@plugin.expects(:say).with("Usage: #{@plugin.usage}")
|
18
|
+
@plugin.expects(:terminate_interaction).returns(true)
|
19
|
+
|
20
|
+
@plugin.execute
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_require_installed_gem_name
|
24
|
+
gemname = "invalid"
|
25
|
+
|
26
|
+
@plugin.expects(:options).returns(:args => [gemname])
|
27
|
+
@plugin.expects(:search).with(gemname).returns(nil)
|
28
|
+
@plugin.expects(:say).with("The #{gemname.inspect} gem couldn't be found")
|
29
|
+
@plugin.expects(:terminate_interaction).returns(true)
|
30
|
+
|
31
|
+
@plugin.execute
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_gem_without_version
|
35
|
+
gemname = "activesupport"
|
36
|
+
|
37
|
+
Gem::SourceIndex.expects(:installed_spec_directories).returns([File.dirname(__FILE__) + "/resources"])
|
38
|
+
|
39
|
+
@plugin.expects(:options).returns(:args => [gemname])
|
40
|
+
@plugin.expects(:system).with("mate #{@gemdir}/activesupport-3.0.0.beta3")
|
41
|
+
|
42
|
+
@plugin.execute
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_gem_with_version
|
46
|
+
gemname = "activesupport-2.3.5"
|
47
|
+
|
48
|
+
Gem::SourceIndex.expects(:installed_spec_directories).returns([File.dirname(__FILE__) + "/resources"])
|
49
|
+
|
50
|
+
@plugin.expects(:options).returns(:args => [gemname])
|
51
|
+
@plugin.expects(:system).with("mate #{@gemdir}/activesupport-2.3.5")
|
52
|
+
|
53
|
+
@plugin.execute
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_unset_editor
|
57
|
+
ENV["GEM_EDITOR"] = nil
|
58
|
+
gemname = "activesupport"
|
59
|
+
|
60
|
+
Gem::SourceIndex.expects(:installed_spec_directories).returns([File.dirname(__FILE__) + "/resources"])
|
61
|
+
|
62
|
+
@plugin.expects(:options).returns(:args => [gemname])
|
63
|
+
@plugin.expects(:say).with("You must set your editor in your .bash_profile or equivalent:")
|
64
|
+
@plugin.expects(:say).with(" export GEM_EDITOR='mate'")
|
65
|
+
@plugin.expects(:terminate_interaction)
|
66
|
+
|
67
|
+
@plugin.execute
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem-open
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Nando Vieira
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-17 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: fnando.vieira@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- lib/rubygems/commands/open.rb
|
33
|
+
- lib/rubygems_plugin.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/fnando/open-gem
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.3.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Open gems into your favorite editor by running a specific gem command.
|
64
|
+
test_files:
|
65
|
+
- test/gem_open_test.rb
|