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

Version Path
groundskeeper-bitcore-0.24.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.23.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.22.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.21.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.20.1 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.19.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.18.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.17.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.16.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.15.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.14.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.13.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.12.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.11.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.10.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.9.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.7.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.6.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.5.0 lib/groundskeeper/changelog.rb
groundskeeper-bitcore-0.4.0 lib/groundskeeper/changelog.rb