Module: SafeMemoize::ReleaseTooling Private
- Defined in:
- lib/safe_memoize/release_tooling.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- VERSION_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/VERSION = "[^"]+"/- SEMVER_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A\d+\.\d+\.\d+(?:[-.][0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?\z/- UNRELEASED_HEADING =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"## [Unreleased]"
Class Method Summary collapse
- .extract_release_notes(contents, version) ⇒ Object private
- .finalize_changelog(contents, version, date = Date.today) ⇒ Object private
- .normalize_version(version) ⇒ Object private
- .update_version_file(contents, version) ⇒ Object private
Class Method Details
.extract_release_notes(contents, version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/safe_memoize/release_tooling.rb', line 49 def extract_release_notes(contents, version) normalized_version = normalize_version(version) lines = contents.lines release_heading = /^## \[#{Regexp.escape(normalized_version)}\](?: - .+)?$/ start_index = lines.index { |line| line.match?(release_heading) } raise ArgumentError, "CHANGELOG.md is missing release notes for #{normalized_version}" unless start_index body = lines[(start_index + 1)..].take_while { |line| !line.start_with?("## [") }.join.strip body = "- No changes listed." if body.empty? <<~MARKDOWN ## SafeMemoize #{normalized_version} #{body} MARKDOWN end |
.finalize_changelog(contents, version, date = Date.today) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/safe_memoize/release_tooling.rb', line 34 def finalize_changelog(contents, version, date = Date.today) normalized_version = normalize_version(version) release_heading = "## [#{normalized_version}] - #{date.iso8601}" unless contents.include?(UNRELEASED_HEADING) raise ArgumentError, "CHANGELOG.md must contain an Unreleased heading" end if contents.match?(/^## \[#{Regexp.escape(normalized_version)}\](?: - .+)?$/) raise ArgumentError, "CHANGELOG.md already contains #{normalized_version}" end contents.sub(UNRELEASED_HEADING, "#{UNRELEASED_HEADING}\n\n#{release_heading}") end |
.normalize_version(version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 17 18 19 20 21 22 |
# File 'lib/safe_memoize/release_tooling.rb', line 14 def normalize_version(version) normalized_version = version.to_s.sub(/\Av/, "") unless normalized_version.match?(SEMVER_PATTERN) raise ArgumentError, "version must look like x.y.z" end normalized_version end |
.update_version_file(contents, version) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
24 25 26 27 28 29 30 31 32 |
# File 'lib/safe_memoize/release_tooling.rb', line 24 def update_version_file(contents, version) normalized_version = normalize_version(version) unless contents.match?(VERSION_PATTERN) raise ArgumentError, "version file does not define VERSION" end contents.sub(VERSION_PATTERN, %(VERSION = "#{normalized_version}")) end |