Sha256: 227734291fe1005ebe97379d4a80ef2e969afa0137792eecb6a998c430a2033f
Contents?: true
Size: 1.07 KB
Versions: 26
Compression:
Stored size: 1.07 KB
Contents
# frozen_string_literal: true require "date" module Groundskeeper # The `CHANGELOG.md` file in an application. class Changelog attr_reader :document, :date FILENAME = "CHANGELOG.md" TITLE_EXPRESSION = "# Changelog" def self.build(filename: FILENAME) new( document: Groundskeeper::Document.new(filename), date: Date.today.iso8601 ) end def initialize(document:, date:) @document = document @date = date end # rubocop:disable Performance/RedundantMatch,Performance/RegexpMatch def update_file(version, changes) unless document.match(/(#{TITLE_EXPRESSION})/) document.prepend_file("#{TITLE_EXPRESSION}\n\n") end document .append_to_file(TITLE_EXPRESSION, version_template(version, changes)) end # rubocop:enable Performance/RedundantMatch,Performance/RegexpMatch private def version_template(version, changes) ["\n", "## #{version} - #{date}", ""] .concat((changes || []).map { |change| "* #{change}" }) .join("\n") end end end
Version data entries
26 entries across 26 versions & 1 rubygems