Class: Paradeiser::PomodoriController

Inherits:
Controller
  • Object
show all
Defined in:
lib/paradeiser/controllers/pomodori_controller.rb

Instance Attribute Summary

Attributes inherited from Controller

#exitstatus, #has_output

Instance Method Summary collapse

Methods inherited from Controller

#call, #get_binding, #initialize, #model, #render

Constructor Details

This class inherits a constructor from Paradeiser::Controller

Instance Method Details

#annotateObject



49
50
51
52
53
54
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 49

def annotate
  raise MissingAnnotationError unless @args && @args.any?
  @pom = Repository.all.select{|p| p.kind_of?(Pomodoro)}.sort{|a,b| a.started_at <=> b.started_at}.last
  @pom.annotate(@args.join(' '))
  Repository.save(@pom)
end

#cancelObject

Raises:



13
14
15
16
17
18
19
20
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 13

def cancel
  @pom = Repository.active
  raise NotActiveError unless @pom
  raise SingletonError.new(Pomodoro, @pom, :finish) if Repository.active? && !@pom.kind_of?(Pomodoro)
  @pom.annotate(@args.join(' ')) if @args.any?
  @pom.cancel!
  Repository.save(@pom)
end

#finishObject

Raises:



22
23
24
25
26
27
28
29
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 22

def finish
  @pom = Repository.active
  raise NotActiveError unless @pom
  raise SingletonError.new(Pomodoro, @pom, :finish) if Repository.active? && !@pom.kind_of?(Pomodoro)
  @pom.annotate(@args.join(' ')) if @args.any?
  @pom.finish!
  Repository.save(@pom)
end

#interruptObject

Raises:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 31

def interrupt
  @pom = Repository.active
  raise NotActiveError unless @pom
  raise SingletonError.new(Pomodoro, @pom, :interrupt) if Repository.active? && !@pom.kind_of?(Pomodoro)

  @pom.annotate(@args.join(' ')) if @args.any?

  if @options.external
    @interrupt_type = 'externally'
    @pom.interrupt!(:external)
  else
    @interrupt_type = 'internally'
    @pom.interrupt!
  end

  Repository.save(@pom)
end

#logObject



56
57
58
59
60
61
62
63
64
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 56

def log
  @pom = Pomodoro.new
  @pom.id = Repository.next_id
  @pom.annotate(@args.join(' ')) if @args.any?
  @pom.status = :finished
  @pom.finished_at = Time.now
  @pom.started_at = @pom.finished_at - Pomodoro::MINUTES_25 * 60
  Repository.save(@pom)
end

#startObject

Raises:



5
6
7
8
9
10
11
# File 'lib/paradeiser/controllers/pomodori_controller.rb', line 5

def start
  end_break
  raise SingletonError.new(Pomodoro, Repository.active, :start) if Repository.active?

  @pom = Pomodoro.new
  Repository.save(@pom)
end