class Chchchanges::Generator
Attributes
changelog[RW]
changelog_hash[RW]
Public Class Methods
new()
click to toggle source
# File lib/chchchanges/generator.rb, line 6 def initialize @changelog_hash = {} @changelog = "# Change Log\n" end
Public Instance Methods
call()
click to toggle source
# File lib/chchchanges/generator.rb, line 11 def call read_changelog_entry_files write_to_changelog_file end
Private Instance Methods
read_changelog_entry_files()
click to toggle source
# File lib/chchchanges/generator.rb, line 18 def read_changelog_entry_files Dir.foreach('.changelog_entries') do |json_file| next if json_file == '.' or json_file == '..' entry = File.read(".changelog_entries/#{json_file}") entry_hash = JSON.parse(entry) version = entry_hash["version"] type = entry_hash["type"] description = entry_hash["description"] ticket = entry_hash["ticket"] @changelog_hash[version] = {} unless changelog_hash[version] @changelog_hash[version][type] = [] unless changelog_hash[version][type] @changelog_hash[version][type] << "- [#{ticket}] #{description}\n" end end
write_to_changelog_file()
click to toggle source
# File lib/chchchanges/generator.rb, line 33 def write_to_changelog_file versions = @changelog_hash.keys.sort_by{|v| Gem::Version.new(v)}.reverse versions.each do |version| change_types = changelog_hash[version] @changelog << "\n## [#{version}]\n" change_types.sort.each do |type, changes| @changelog << "### #{type}\n" changes.sort.each do |change| @changelog << change end end end File.write('CHANGELOG.md', @changelog) end