class Tlog::Command::Stop

Public Instance Methods

description() click to toggle source
# File lib/tlog/command/stop.rb, line 8
def description
  "ends a task for a time log"
end
execute(input, output) click to toggle source
# File lib/tlog/command/stop.rb, line 12
def execute(input, output)
  updated_log = stop
  output.line("Stopped '#{updated_log.name}'")
  current_branch = storage.current_branch
  if input.options[:all]
    commit_output = commit_working_changes(input.options[:message])
    commit_message = input.options[:message]
    output.line("#{commit_output}")
  end
end
name() click to toggle source
# File lib/tlog/command/stop.rb, line 4
def name 
  "stop"
end
options(parser, options) click to toggle source
# File lib/tlog/command/stop.rb, line 23
def options(parser, options)
  parser.banner = "usage: tlo stop"

  parser.on("-a", "--all", "Stop current time log and commit tracked working changes") do |all|
    options[:all] = all
  end

  parser.on("-m", "--message <commit_message>", "The commit message you want to be associated with this commit") do |message|
    options[:message] = message
  end
end

Private Instance Methods

commit_working_changes(message) click to toggle source
# File lib/tlog/command/stop.rb, line 50
def commit_working_changes(message)
  storage.commit_working_changes(message)
end
stop() click to toggle source
# File lib/tlog/command/stop.rb, line 37
def stop
  storage.in_branch do |wd|
    checked_out_log = storage.checkout_value
    raise Tlog::Error::CheckoutInvalid, "No time log is checked out" unless checked_out_log
    log = storage.require_log(checked_out_log)
    raise Tlog::Error::TimeLogNotFound, "Time log '#{checked_out_log}' does not exist" unless log
    unless storage.stop_log(log)
      raise Tlog::Error::CommandInvalid, "Failed to stop log '#{checked_out_log}': This time log is not in progress"
    end
    log
  end
end