Class: Gem::Commands::ReadmeCommand
- Inherits:
-
Gem::Command
- Object
- Gem::Command
- Gem::Commands::ReadmeCommand
- Includes:
- VersionOption
- Defined in:
- lib/gem_readme/readme_command.rb
Constant Summary collapse
- OPTIONS =
{ :version => Gem::Requirement.default, :editor => 'less' }
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
-
#defaults_str ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ ReadmeCommand
constructor
A new instance of ReadmeCommand.
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ ReadmeCommand
Returns a new instance of ReadmeCommand.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gem_readme/readme_command.rb', line 13 def initialize super 'readme', 'Open a README of an installed gem', OPTIONS add_version_option add_option('-e', '--editor EDITOR', String, 'The editor to use to open the gems', "Default: #{OPTIONS[:editor]}") do |editor, | [:editor] = editor end end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
25 26 27 |
# File 'lib/gem_readme/readme_command.rb', line 25 def arguments # :nodoc: "GEMNAME name of gem to open README" end |
#defaults_str ⇒ Object
:nodoc:
29 30 31 |
# File 'lib/gem_readme/readme_command.rb', line 29 def defaults_str # :nodoc: "--version '#{OPTIONS[:version]}' --editor #{OPTIONS[:editor]}" end |
#execute ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gem_readme/readme_command.rb', line 37 def execute version = [:version] || OPTIONS[:version] gem_specs = get_all_gem_names.map { |gem_name| Gem.source_index.find_name(gem_name, version).last }.compact if gem_specs.size > 0 paths = gem_specs.map { |spec| spec.full_gem_path } readmes = paths.inject([]) do |result, path| result + Dir[File.join(path, '*')].select{ |i| File.basename(i) =~ /^readme/i } end if readmes.empty? say "README not found!" exit! end cmd = "#{[:editor]} #{readmes.join(' ')}" exec cmd unless [:dryrun] else say "No gems found for #{get_all_gem_names.join(', ')}" raise Gem::SystemExitException, 1 end end |
#usage ⇒ Object
:nodoc:
33 34 35 |
# File 'lib/gem_readme/readme_command.rb', line 33 def usage # :nodoc: "#{program_name} [options] GEMNAME [GEMNAME ...]" end |