Class: Gem::Commands::OpenCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::OpenCommand
- Includes:
- VersionOption
- Defined in:
- lib/rubygems/commands/open_command.rb
Instance Attribute Summary
Attributes inherited from Gem::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
-
#description ⇒ Object
:nodoc:.
- #execute ⇒ Object
- #get_env_editor ⇒ Object
-
#initialize ⇒ OpenCommand
constructor
A new instance of OpenCommand.
- #open_editor(path) ⇒ Object
- #open_gem(name) ⇒ Object
- #spec_for(name) ⇒ Object
-
#usage ⇒ Object
:nodoc:.
Methods included from VersionOption
#add_platform_option, #add_prerelease_option, #add_version_option
Methods inherited from Gem::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, extra_args, extra_args=, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction, #verbose
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ OpenCommand
Returns a new instance of OpenCommand.
10 11 12 13 14 15 16 17 |
# File 'lib/rubygems/commands/open_command.rb', line 10 def initialize super 'open', 'Open gem sources in editor' add_option('-e', '--editor EDITOR', String, "Opens gem sources in EDITOR") do |editor, | [:editor] = editor || get_env_editor end end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
19 20 21 |
# File 'lib/rubygems/commands/open_command.rb', line 19 def arguments # :nodoc: "GEMNAME name of gem to open in editor" end |
#defaults_str ⇒ Object
:nodoc:
23 24 25 |
# File 'lib/rubygems/commands/open_command.rb', line 23 def defaults_str # :nodoc: "-e #{get_env_editor}" end |
#description ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 |
# File 'lib/rubygems/commands/open_command.rb', line 27 def description # :nodoc: <<-EOF The open command opens gem in editor and changes current path to gem's source directory. Editor can be specified with -e option, otherwise rubygems will look for editor in $EDITOR, $VISUAL and $GEM_EDITOR variables. EOF end |
#execute ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rubygems/commands/open_command.rb', line 47 def execute @version = [:version] || Gem::Requirement.default @editor = [:editor] || get_env_editor found = open_gem(get_one_gem_name) terminate_interaction 1 unless found end |
#get_env_editor ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rubygems/commands/open_command.rb', line 40 def get_env_editor ENV['GEM_EDITOR'] || ENV['VISUAL'] || ENV['EDITOR'] || 'vi' end |
#open_editor(path) ⇒ Object
63 64 65 66 67 |
# File 'lib/rubygems/commands/open_command.rb', line 63 def open_editor path Dir.chdir(path) do system(*@editor.split(/\s+/) + [path]) end end |
#open_gem(name) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/rubygems/commands/open_command.rb', line 56 def open_gem name spec = spec_for name return false unless spec open_editor(spec.full_gem_path) end |
#spec_for(name) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/rubygems/commands/open_command.rb', line 69 def spec_for name spec = Gem::Specification.find_all_by_name(name, @version).last return spec if spec say "Unable to find gem '#{name}'" end |
#usage ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/rubygems/commands/open_command.rb', line 36 def usage # :nodoc: "#{program_name} GEMNAME [-e EDITOR]" end |