Class: MetaCommit::Changelog::Adapters::Changelog

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

Overview

Adapter class to write repository changes to changelog file

Constant Summary collapse

VERSION_DELIMITER =
"\n\n\n"
VERSION_HEADER_REGEX =
/(## \[.*?\] - \d{4}-\d{2}-\d{2})/m

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, filename, tag, date) ⇒ Changelog

Returns a new instance of Changelog.

Parameters:

  • path (String)
  • filename (String)
  • tag (String)

    version

  • date (String)

    of version release



14
15
16
17
18
19
# File 'lib/meta_commit/changelog/adapters/changelog.rb', line 14

def initialize(path, filename, tag, date)
  @path=path
  @filename=filename
  @tag=tag
  @date=date
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



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

def date
  @date
end

#filenameObject

Returns the value of attribute filename.



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

def filename
  @filename
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#tagObject

Returns the value of attribute tag.



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

def tag
  @tag
end

Instance Method Details

#write_repository_change_chunk(repo, diffs) ⇒ String

Builds changelog message and adds it after description text and before latest version

Parameters:

  • repo
  • diffs (Array<MetaCommit::Contracts::Diff>)

Returns:

  • (String)


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

def write_repository_change_chunk(repo, diffs)
  message_builder = changelog_message_builder(@tag, @date)
  diffs.each do |diff|
    message_builder.add_to_added(diff.string_representation) if diff.type_addition?
    message_builder.add_to_removed(diff.string_representation) if diff.type_deletion?
    message_builder.add_to_changed(diff.string_representation) if diff.type_replace?
  end
  prepend_to_changelog(message_builder.build)
end