Class: Changelog

Inherits:
Object
  • Object
show all
Defined in:
lib/changelog.rb

Overview

Central class that puts together the changelog.

Constant Summary collapse

@@tags =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChangelog

Returns a new instance of Changelog.



24
25
26
# File 'lib/changelog.rb', line 24

def initialize
	@recent_changes_heading = "Unpublished changes"
end

Instance Attribute Details

#recent_changes_heading=(value) ⇒ Object (writeonly)

Heading for the most recent changes.



22
23
24
# File 'lib/changelog.rb', line 22

def recent_changes_heading=(value)
  @recent_changes_heading = value
end

Instance Method Details

#generate(exclude_recent = false) ⇒ String

Generates a decorated changelog for the entire commit history.

Parameters:

  • exclude_recent (bool) (defaults to: false)

    Indicates whether to exclude recent changelog lines that were added since the last tag.

Returns:

  • (String)

    Decorated changelog, or nil if no lines were found.



39
40
41
42
43
44
45
46
47
# File 'lib/changelog.rb', line 39

def generate(exclude_recent = false)
	# Traverse tags
	@@tags = TagList.new(!exclude_recent)
	output = String.new
	@@tags.list.each_cons(2) do |current_tag, previous_tag|
		output << generate_for(current_tag, previous_tag)
	end
	output.length > 0 ? output : nil
end

#generate_recentArray

Generates a simple, undecorated list of changelog entries since the most recent tag.

Returns:

  • (Array)

    Array of changelog lines, or nil if no lines were found.



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/changelog.rb', line 55

def generate_recent
	@@tags = TagList.new
	log = CommitChangelog.new(@@tags.list[0], @@tags.list[1])
	# Explicitly add initial commit if there is no tag yet
	# This is necessary because HEAD..OTHER_COMMIT does not include
	# OTHER_COMMIT's message, which is the desired behavior if
	# OTHER_COMMIT is a tag for a previous version, but undesired
	# if OTHER_COMMIT is the initial commit of the repository.
	log.add_commit @@tags.list[1] if @@tags.list.length == 2
	log.changelog
end