class Codelog::Command::Setup

Constants

CHANGELOG_DEFAULT_PATH
CHANGELOG_DESTINATION_PATH
CONFIG_FILE_PATH
HEADER_FILE_PATH
TEMPLATE_FILE_PATH

Public Class Methods

run() click to toggle source
# File lib/codelog/command/setup.rb, line 15
def self.run
  Codelog::Command::Setup.new.run
end

Public Instance Methods

run() click to toggle source
# File lib/codelog/command/setup.rb, line 19
def run
  chdir Dir.pwd do
    # This script provides the initial setup for the gem usage.
    puts '== Creating folder structure and template =='
    create_folder_structure
    puts '== Copying fixtures =='
    copy_fixtures
    handle_existing_changelog
  end
end

Private Instance Methods

copy_and_mark_changelog() click to toggle source
# File lib/codelog/command/setup.rb, line 61
def copy_and_mark_changelog
  File.open(CHANGELOG_DEFAULT_PATH, 'rb') do |orig|
    File.open(CHANGELOG_DESTINATION_PATH, 'wb') do |dest|
      dest.write("<!-- Old changelog starts here -->\n\n")
      dest.write(orig.read)
    end
  end
end
copy_fixtures() click to toggle source
# File lib/codelog/command/setup.rb, line 40
def copy_fixtures
  system! "cp #{TEMPLATE_FILE_PATH} changelogs/template.yml"
  system! "cp #{CONFIG_FILE_PATH} changelogs/codelog.yml"
  system! "cp #{HEADER_FILE_PATH} changelogs/header.txt"
end
create_folder_structure() click to toggle source
# File lib/codelog/command/setup.rb, line 32
def create_folder_structure
  system! 'mkdir changelogs/'
  system! 'mkdir changelogs/unreleased'
  system! 'mkdir changelogs/releases'
  system! 'touch changelogs/unreleased/.gitkeep'
  system! 'touch changelogs/releases/.gitkeep'
end
handle_existing_changelog() click to toggle source
# File lib/codelog/command/setup.rb, line 46
def handle_existing_changelog
  return unless old_changelog_exists?
  if yes? Codelog::Message::Warning.maintain_versioning_of_existing_changelog?
    puts '== Copying existing changelog to releases folder =='
    copy_and_mark_changelog
  elsif yes? Codelog::Message::Warning.delete_existing_changelog?
    puts '== Deleting existing changelog =='
    system! "rm #{CHANGELOG_DEFAULT_PATH}"
  end
end
old_changelog_exists?() click to toggle source
# File lib/codelog/command/setup.rb, line 57
def old_changelog_exists?
  File.file?(CHANGELOG_DEFAULT_PATH)
end
receive(stdin: $stdin) click to toggle source
# File lib/codelog/command/setup.rb, line 79
def receive(stdin: $stdin)
  stdin.gets.chomp.casecmp('y').zero?
end
system!(*args) click to toggle source
# File lib/codelog/command/setup.rb, line 70
def system!(*args)
  system(*args) || puts("\n== Command #{args} was skipped ==")
end
yes?(args) click to toggle source
# File lib/codelog/command/setup.rb, line 74
def yes?(args)
  puts(args)
  receive
end