Class: Gem::Commands::HistoryCommand

Inherits:
Gem::Command
  • Object
show all
Includes:
VersionOption, GemToolbox::CommonOptions
Defined in:
lib/rubygems/commands/history_command.rb

Overview

HistoryCommand displays the gem’s changelog using $GEM_PAGER or $PAGER

Constant Summary collapse

CHANGELOG_PATTERN =
/^(history|changelog|changes)/i

Instance Method Summary collapse

Methods included from GemToolbox::CommonOptions

#add_command_option, #add_exact_match_option, #add_latest_version_option, #get_path, #get_spec, #show

Constructor Details

#initializeHistoryCommand

Returns a new instance of HistoryCommand.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rubygems/commands/history_command.rb', line 10

def initialize
  super "history", "Show gem's changelog using $GEM_PAGER or $PAGER",
    :command => nil, 
    :version => Gem::Requirement.default,
    :latest  => false
  
  add_latest_version_option
  add_exact_match_option
  add_version_option
  add_command_option
end

Instance Method Details

#argumentsObject

:nodoc:



22
23
24
# File 'lib/rubygems/commands/history_command.rb', line 22

def arguments # :nodoc:
  "GEMNAME      Gem to show changelog for"
end

#executeObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubygems/commands/history_command.rb', line 26

def execute
  name = get_one_optional_argument
  path = get_path(name)
  
  if path
    if log = find_changelog(path)
      show log
    else
      say "No changelog found for #{name}"
    end
  end
end

#find_changelog(path) ⇒ Object



39
40
41
42
43
44
# File 'lib/rubygems/commands/history_command.rb', line 39

def find_changelog(path)
  Dir.glob(File.join(path, "*")).each do |file|
    return file if File.file?(file) && File.basename(file) =~ CHANGELOG_PATTERN
  end
  nil
end