class Logchange::Logger

Logs a new change.

Public Class Methods

new(title, template: Logchange::Template.load) click to toggle source
# File lib/logchange/logger.rb, line 9
def initialize(title, template: Logchange::Template.load)
  @title = title
  @template = template
end

Public Instance Methods

execute() click to toggle source
# File lib/logchange/logger.rb, line 14
def execute
  file_path = File.join(unreleased_path, filename)
  File.write(file_path, log_contents)
  puts "Created #{file_path}"
end

Private Instance Methods

datetime() click to toggle source
# File lib/logchange/logger.rb, line 43
def datetime
  "#{Time.now.utc.year}#{Time.now.utc.month.to_s.rjust(2, '0')}#{Time.now.utc.day.to_s.rjust(2, '0')}"
end
filename() click to toggle source
# File lib/logchange/logger.rb, line 29
def filename
  "#{datetime}-#{simplified_title}.yaml"
end
log_contents() click to toggle source
# File lib/logchange/logger.rb, line 22
def log_contents
  YAML.dump({
    'timestamp' => Time.now.utc.iso8601,
    'title' => @title
  }.merge(@template))
end
simplified_title() click to toggle source
# File lib/logchange/logger.rb, line 33
def simplified_title
  spaces_dashed = @title.tr(' ', '-')
  specials_removed = spaces_dashed.gsub(/[^\-0-9A-Za-z]/, '')[0..60]
  specials_removed.downcase
end
unreleased_path() click to toggle source
# File lib/logchange/logger.rb, line 39
def unreleased_path
  File.join(Logchange.configuration.changelog_directory_path, 'unreleased')
end