Class: Reissue::ChangelogUpdater
- Inherits:
-
Object
- Object
- Reissue::ChangelogUpdater
- Defined in:
- lib/reissue/changelog_updater.rb
Overview
Updates the changelog file with new versions and changes.
Instance Attribute Summary collapse
-
#changelog ⇒ Object
readonly
Returns the value of attribute changelog.
Instance Method Summary collapse
-
#call(version, date: "Unreleased", changes: {}, changelog_file: @changelog_file, version_limit: 2) ⇒ Object
Updates the changelog with a new version and its changes.
- #finalize(date: Date.today, changelog_file: @changelog_file) ⇒ Object
-
#initialize(changelog_file) ⇒ ChangelogUpdater
constructor
A new instance of ChangelogUpdater.
-
#reformat(result_file = @changelog_file, version_limit: 2) ⇒ Hash
Reformats the changelog file to ensure it is correctly formatted.
-
#to_s ⇒ String
Returns the string representation of the changelog.
-
#update(version, date: "Unreleased", changes: {}, version_limit: 2) ⇒ Hash
Updates the changelog with a new version and its changes.
-
#write(changelog_file = @changelog_file) ⇒ Object
Writes the changelog to the specified file.
Constructor Details
#initialize(changelog_file) ⇒ ChangelogUpdater
Returns a new instance of ChangelogUpdater.
7 8 9 10 |
# File 'lib/reissue/changelog_updater.rb', line 7 def initialize(changelog_file) @changelog_file = changelog_file @changelog = {} end |
Instance Attribute Details
#changelog ⇒ Object (readonly)
Returns the value of attribute changelog.
12 13 14 |
# File 'lib/reissue/changelog_updater.rb', line 12 def changelog @changelog end |
Instance Method Details
#call(version, date: "Unreleased", changes: {}, changelog_file: @changelog_file, version_limit: 2) ⇒ Object
Updates the changelog with a new version and its changes.
21 22 23 24 25 |
# File 'lib/reissue/changelog_updater.rb', line 21 def call(version, date: "Unreleased", changes: {}, changelog_file: @changelog_file, version_limit: 2) update(version, date:, changes:, version_limit:) write(changelog_file) changelog end |
#finalize(date: Date.today, changelog_file: @changelog_file) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/reissue/changelog_updater.rb', line 27 def finalize(date: Date.today, changelog_file: @changelog_file) @changelog = Parser.parse(File.read(changelog_file)) # find the highest version number and if it is unreleased, update the date version = changelog["versions"].max_by { |v| ::Gem::Version.new(v["version"]) } version_date = version["date"] if version_date.nil? || version_date == "Unreleased" changelog["versions"].find do |v| v["version"] == version["version"] end["date"] = date end write changelog end |
#reformat(result_file = @changelog_file, version_limit: 2) ⇒ Hash
Reformats the changelog file to ensure it is correctly formatted.
60 61 62 63 64 65 |
# File 'lib/reissue/changelog_updater.rb', line 60 def reformat(result_file = @changelog_file, version_limit: 2) @changelog = Parser.parse(File.read(@changelog_file)) changelog["versions"] = changelog["versions"].first(version_limit) write(result_file) changelog end |
#to_s ⇒ String
Returns the string representation of the changelog.
70 71 72 |
# File 'lib/reissue/changelog_updater.rb', line 70 def to_s Printer.new(changelog).to_s end |
#update(version, date: "Unreleased", changes: {}, version_limit: 2) ⇒ Hash
Updates the changelog with a new version and its changes.
48 49 50 51 52 53 54 |
# File 'lib/reissue/changelog_updater.rb', line 48 def update(version, date: "Unreleased", changes: {}, version_limit: 2) @changelog = Parser.parse(File.read(@changelog_file)) changelog["versions"].unshift({"version" => version, "date" => date, "changes" => changes}) changelog["versions"] = changelog["versions"].first(version_limit) changelog end |
#write(changelog_file = @changelog_file) ⇒ Object
Writes the changelog to the specified file.
77 78 79 |
# File 'lib/reissue/changelog_updater.rb', line 77 def write(changelog_file = @changelog_file) File.write(changelog_file, to_s) end |