Class: Cmd::CompleteTask

Inherits:
Object
  • Object
show all
Defined in:
lib/cmd/complete.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, logger, stdout, stderr) ⇒ CompleteTask

Returns a new instance of CompleteTask.



6
7
8
9
10
11
# File 'lib/cmd/complete.rb', line 6

def initialize(db, logger, stdout, stderr)
  @db = db
  @logger = logger
  @stdout = stdout
  @stderr = stderr
end

Instance Method Details

#call(args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/cmd/complete.rb', line 13

def call(args)
  options = parse(args)
  todo = @db[:todos].where(id: options[:id]).first
  if todo.nil?
    @stderr.puts "Not found"
    exit(1)
  end
  @db[:todos].where(id: options[:id]).update(done: true, completed_on: Date.today)
  @stdout.puts "Task completed"
end