Module: Commands::Start

Included in:
LogTime
Defined in:
lib/commands/start.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/commands/start.rb', line 3

def self.included(thor)
    thor.class_eval do
    desc "start [NAME]", "Start new timer"
    def start(name)
      log = Log.find_by(name: name)

      # not found
      if !log
        say "#{name} not found", :red
        exit
      end

      # already active?
      if log.active?
        say "#{name} already active", :red
        exit
      end

      # begin new series, activate log
      # Series.start!(log_id: log.id)
      if log.start!
        started_at = time_display(Time.now)
        say "#{name} started at #{started_at}", :green
      else
        say "#{name} failed to start", :red
      end
    end
  end
end