Class: Groundskeeper::Changelog

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

Overview

The ‘CHANGELOG.md` file in an application.

Constant Summary collapse

FILENAME =
"CHANGELOG.md"
TITLE_EXPRESSION =
"# Changelog"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, date:) ⇒ Changelog

Returns a new instance of Changelog.



20
21
22
23
# File 'lib/groundskeeper/changelog.rb', line 20

def initialize(document:, date:)
  @document = document
  @date = date
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



8
9
10
# File 'lib/groundskeeper/changelog.rb', line 8

def date
  @date
end

#documentObject (readonly)

Returns the value of attribute document.



8
9
10
# File 'lib/groundskeeper/changelog.rb', line 8

def document
  @document
end

Class Method Details

.build(filename: FILENAME) ⇒ Object



13
14
15
16
17
18
# File 'lib/groundskeeper/changelog.rb', line 13

def self.build(filename: FILENAME)
  new(
    document: Groundskeeper::Document.new(filename),
    date: Date.today.iso8601
  )
end

Instance Method Details

#update_file(version, changes) ⇒ Object

rubocop:disable Performance/RedundantMatch,Performance/RegexpMatch



26
27
28
29
30
31
32
33
# File 'lib/groundskeeper/changelog.rb', line 26

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