Class: Changelog::Writer

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

Overview

Class responsible for writing the change logs and collating them.

Class Method Summary collapse

Class Method Details

.archive_old_change_logObject



23
24
25
26
27
28
29
# File 'lib/changelog/writer.rb', line 23

def self.archive_old_change_log
  system('mkdir -p changelogs')
  date_str = Time.now.strftime('%b-%d-%Y-%H-%M-%S')
  old_change_log_location = "changelogs/archive-#{date_str}.md"
  system("mv #{::CHANGE_LOG_NAME} #{old_change_log_location}")
  puts 'Archive old Changelog'
end

.call(collection, no_archive = false) ⇒ Object



5
6
7
8
9
10
# File 'lib/changelog/writer.rb', line 5

def self.call(collection, no_archive = false)
  generate_change_log(collection)
  archive_old_change_log unless no_archive
  publish_change_log
  clear_unreleased_logs
end

.clear_unreleased_logsObject



36
37
38
39
40
# File 'lib/changelog/writer.rb', line 36

def self.clear_unreleased_logs
  puts 'Clearing changelogs/unreleased'
  system('rm changelogs/unreleased/*')
  system('rmdir changelogs/unreleased')
end

.generate_change_log(collection) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/changelog/writer.rb', line 12

def self.generate_change_log(collection)
  File.open(TEMP_CHANGE_LOG_NAME, 'w') do |file|
    write_title(file)
    TYPES.each do |type|
      write_collection(type, collection, file)
    end
    file.puts ''
  end
  puts "Creating temporary file  #{::TEMP_CHANGE_LOG_NAME}"
end

.publish_change_logObject



31
32
33
34
# File 'lib/changelog/writer.rb', line 31

def self.publish_change_log
  system("mv #{::TEMP_CHANGE_LOG_NAME} #{::CHANGE_LOG_NAME}")
  puts "Renamed #{::TEMP_CHANGE_LOG_NAME} to #{::CHANGE_LOG_NAME}"
end

.write_collection(type, collection, file) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/changelog/writer.rb', line 46

def self.write_collection(type, collection, file)
  lines = collection[type.name]
  size = lines.size

  return if size.zero?

  file.puts("## #{type.name.capitalize} (#{size} count/s)\n")

  write_lines(lines, file)
end

.write_lines(lines, file) ⇒ Object



57
58
59
60
61
# File 'lib/changelog/writer.rb', line 57

def self.write_lines(lines, file)
  lines.each do |line|
    file.puts("  + #{line.title} - #{line.author}")
  end
end

.write_title(file) ⇒ Object



42
43
44
# File 'lib/changelog/writer.rb', line 42

def self.write_title(file)
  file.puts("# Changelogs \n")
end