open_gem 1.2.0 → 1.3.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.
@@ -0,0 +1,15 @@
1
+ OpenGem
2
+ ========
3
+
4
+ 1.3
5
+ ----
6
+ * Added the read command for your reading pleasure.
7
+ Very similar to open, except it will launch the rdoc files for the gem, or generate them.
8
+
9
+ 1.2
10
+ ----
11
+ * Fixed shell parsing so that commands can include arguments
12
+
13
+ 1.0
14
+ ----
15
+ * Initial release!
data/README.markdown CHANGED
@@ -5,6 +5,10 @@ Simply opens the specified gem in your default editor.
5
5
 
6
6
  gem open rails
7
7
 
8
+ If you just want to read documentation you can do:
9
+
10
+ gem read activerecord
11
+
8
12
  Installation:
9
13
  ------------
10
14
  OpenGem require rubygems 1.3.2 or higher. You may need
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 0
3
2
  :major: 1
4
- :minor: 2
3
+ :minor: 3
4
+ :patch: 0
@@ -0,0 +1,36 @@
1
+ module OpenGem
2
+ module CommonOptions
3
+ def add_command_option(description=nil)
4
+ add_option('-c', '--command COMMAND',
5
+ description || 'Execute command at path of the rubygem') do |value, options|
6
+ options[:command] = value
7
+ end
8
+ end
9
+
10
+ def add_latest_version_option
11
+ add_option('-l', '--latest',
12
+ 'If there are multiple versions, open the latest') do |value, options|
13
+ options[:latest] = true
14
+ end
15
+ end
16
+
17
+ def get_spec(name)
18
+ dep = Gem::Dependency.new name, options[:version]
19
+ specs = Gem.source_index.search(dep).select{|spec| spec.has_rdoc?}
20
+
21
+ if specs.length == 0
22
+ say "Could not find docs for '#{name}'"
23
+ return nil
24
+
25
+ elsif specs.length == 1 || options[:latest]
26
+ return specs.last
27
+
28
+ else
29
+ choices = specs.map{|s|"#{s.name} #{s.version}"}
30
+ c,i = choose_from_list "Open which gem?", choices
31
+ return specs[i] if i
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,11 +1,6 @@
1
- require 'shellwords'
2
-
3
- require 'rubygems/command'
4
- require 'rubygems/dependency'
5
- require 'rubygems/version_option'
6
-
7
1
  # OpenCommand will open a gem's source path
8
2
  class Gem::Commands::OpenCommand < Gem::Command
3
+ include OpenGem::CommonOptions
9
4
  include Gem::VersionOption
10
5
 
11
6
  def initialize
@@ -14,16 +9,8 @@ class Gem::Commands::OpenCommand < Gem::Command
14
9
  :version=> Gem::Requirement.default,
15
10
  :latest=> false
16
11
 
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
-
12
+ add_command_option
13
+ add_latest_version_option
27
14
  add_version_option
28
15
  end
29
16
 
@@ -39,21 +26,8 @@ class Gem::Commands::OpenCommand < Gem::Command
39
26
  end
40
27
 
41
28
  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
-
29
+ if spec = get_spec(name)
30
+ spec.full_gem_path
57
31
  end
58
32
  end
59
33
 
@@ -0,0 +1,60 @@
1
+ # ReadCommand will open a gem's rdoc
2
+ class Gem::Commands::ReadCommand < Gem::Command
3
+ include OpenGem::CommonOptions
4
+ include Gem::VersionOption
5
+
6
+ def initialize
7
+ super 'read', "Opens the gem's documentation",
8
+ :command => nil,
9
+ :version=> Gem::Requirement.default,
10
+ :latest=> false
11
+
12
+ add_command_option "Application to read rdoc with"
13
+ add_latest_version_option
14
+ add_version_option
15
+ end
16
+
17
+ def arguments # :nodoc:
18
+ "GEMNAME gem to read"
19
+ end
20
+
21
+ def execute
22
+ name = get_one_gem_name
23
+ spec = get_spec name
24
+ if spec && path = get_path(spec)
25
+ if File.exists? path
26
+ read_gem path
27
+ elsif ask_yes_no "The rdoc seems to be missing, would you like to generate one?", true
28
+ generate_rdoc spec
29
+ read_gem path
30
+ end
31
+ end
32
+ end
33
+
34
+ def get_path(spec)
35
+ File.join(spec.installation_path, "doc", spec.full_name, 'rdoc','index.html')
36
+ end
37
+
38
+ def generate_rdoc spec
39
+ Gem::DocManager.new(spec).generate_rdoc
40
+ end
41
+
42
+ def rdoc_reader
43
+ options[:command] || case RUBY_PLATFORM.downcase
44
+ when /darwin/ then 'open'
45
+ when /mswin/ then 'explorer'
46
+ when /linux/ then 'firefox'
47
+ else 'firefox' # Come on, if you write ruby, you probably have firefox installed ;)
48
+ end
49
+ end
50
+
51
+ def read_gem(path)
52
+ command_parts = Shellwords.shellwords(rdoc_reader)
53
+ command_parts << path
54
+ success = system(*command_parts)
55
+ if !success
56
+ raise Gem::CommandLineError, "Could not run '#{editor} #{path}', exit code: #{$?.exitstatus}"
57
+ end
58
+ end
59
+
60
+ end
@@ -1,3 +1,11 @@
1
1
  require 'rubygems/command_manager'
2
2
 
3
- Gem::CommandManager.instance.register_command :open
3
+ require 'rubygems/command'
4
+ require 'rubygems/dependency'
5
+ require 'rubygems/version_option'
6
+
7
+ require 'shellwords'
8
+ require 'open_gem/common_options'
9
+
10
+ Gem::CommandManager.instance.register_command :open
11
+ Gem::CommandManager.instance.register_command :read
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Sanderson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-02 00:00:00 -07:00
12
+ date: 2009-06-02 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -31,10 +31,13 @@ extensions: []
31
31
  extra_rdoc_files:
32
32
  - README.markdown
33
33
  files:
34
+ - CHANGELOG.markdown
34
35
  - README.markdown
35
36
  - Rakefile
36
37
  - VERSION.yml
38
+ - lib/open_gem/common_options.rb
37
39
  - lib/rubygems/commands/open_command.rb
40
+ - lib/rubygems/commands/read_command.rb
38
41
  - lib/rubygems_plugin.rb
39
42
  - test/open_command_test.rb
40
43
  has_rdoc: false