class Logchange::Dispatch

Routes the user's command to appropriate handler.

Public Instance Methods

execute() click to toggle source
# File lib/logchange/dispatch.rb, line 4
def execute
  ensure_changelog_directory_exists if %i[new release].include?(command)

  case command
    when :init
      Logchange::Initialize.new.execute
    when :new
      if ARGV[1].nil?
        Logchange::InteractiveLogger.new.execute
      else
        Logchange::Logger.new(ARGV[1]).execute
      end
    when :release
      Logchange::Release.new(ARGV[1]).execute
    else
      print_help
  end
end

Private Instance Methods

command() click to toggle source
# File lib/logchange/dispatch.rb, line 31
def command
  return ARGV[0].to_sym if %w[init new release].include?(ARGV[0])
  :unknown
end
ensure_changelog_directory_exists() click to toggle source
# File lib/logchange/dispatch.rb, line 25
def ensure_changelog_directory_exists
  path = File.join(Logchange.configuration.changelog_directory_path, 'unreleased')
  return if File.directory?(path)
  abort("The changelog directory does not exist in this path. Run 'logchange init', or change to the correct path.")
end
print_help() click to toggle source