Class: Gem::Commands::OpenCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::OpenCommand
- Includes:
- VersionOption, OpenGem::CommonOptions
- Defined in:
- lib/rubygems/commands/open_command.rb
Overview
OpenCommand will open a gem’s source path
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
- #execute ⇒ Object
- #get_path(name) ⇒ Object
-
#initialize ⇒ OpenCommand
constructor
A new instance of OpenCommand.
- #open_gem(path) ⇒ Object
Methods included from OpenGem::CommonOptions
#add_command_option, #add_exact_match_option, #add_latest_version_option, #get_spec
Constructor Details
#initialize ⇒ OpenCommand
Returns a new instance of OpenCommand.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubygems/commands/open_command.rb', line 10 def initialize super 'open', "Opens the gem's source directory with $GEM_OPEN_EDITOR or $EDITOR", :command => nil, :version=> Gem::Requirement.default, :latest=> false add_command_option add_latest_version_option add_version_option add_exact_match_option end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/rubygems/commands/open_command.rb', line 22 def arguments # :nodoc: "GEMNAME gem to open" end |
#execute ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rubygems/commands/open_command.rb', line 26 def execute name = get_one_gem_name path = get_path(name) open_gem(path) if path end |
#get_path(name) ⇒ Object
33 34 35 36 37 |
# File 'lib/rubygems/commands/open_command.rb', line 33 def get_path(name) if spec = get_spec(name) spec.full_gem_path end end |
#open_gem(path) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubygems/commands/open_command.rb', line 39 def open_gem(path) editor = [:command] || ENV['GEM_OPEN_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] if !editor say "Either set $GEM_OPEN_EDITOR, $VISUAL, $EDITOR, or use -c <command_name>" else command_parts = Shellwords.shellwords(editor) command_parts << path success = system(*command_parts) if !success raise Gem::CommandLineError, "Could not run '#{editor} #{path}', exit code: #{$?.exitstatus}" end end end |