Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Everything seems to be in order. Time for testing!

  • Loading branch information...
commit 014c65d7746ba8a478f409bb441e8159d7ada37c 1 parent ba53e0d
@steveklabnik authored
Showing with 23 additions and 17 deletions.
  1. +7 −0 bin/pomodoro
  2. +10 −12 lib/pomodoro.rb
  3. +6 −5 spec/pomodoro_spec.rb
View
7 bin/pomodoro
@@ -4,9 +4,16 @@ require './lib/pomodoro'
require 'thin'
rackup_file = "./lib/pomodoro/config.ru"
+
+Thread.new do
+ loop do
+ Pomodoro.work
+ end
+end
argv = ARGV
argv << ["-R", rackup_file] unless ARGV.include?("-R")
argv << ["-p", "80"] unless ARGV.include?("-p")
argv << ["-e", "production"] unless ARGV.include?("-e")
Thin::Runner.new(argv.flatten).run!
+
View
22 lib/pomodoro.rb
@@ -9,32 +9,30 @@ def start!
Noprocrast.activate!
@start_time = Time.now
work_growl
+ @stopped = false
end
def stop!
Noprocrast.deactivate!
break_growl
+ @stopped = true
end
- def work interval=5
+ def work
@start_time = Time.now if @start_time.nil?
- loop do
- elapsed_time = Time.now - @start_time
- if elapsed_time >= 1800 # 25 minutes * 60 seconds
- start!
- elsif elapsed_time >= 1500 # 30 minutes * 60 seconds
- stop!
- end
- break if interval == 0 #this lets us test one run-through
- sleep interval * 60
+ elapsed_time = Time.now - @start_time
+ if elapsed_time >= 1800 && @stopped == true # 30 minutes * 60 seconds
+ start!
+ elsif elapsed_time >= 1500 && @stopped == false # 25 minutes * 60 seconds
+ stop!
end
end
def break_growl
- system 'growlnotify -w -n Pomodoro -m "You have 5 minutes." "BREAK TIME" -s'
+ system 'growlnotify -w -n Pomodoro -m "You have 5 minutes." "BREAK TIME"'
end
def work_growl
- system 'growlnotify -w -n Pomodoro -m "This lasts 25 minutes." "WORK TIME" -s'
+ system 'growlnotify -w -n Pomodoro -m "This lasts 25 minutes." "WORK TIME"'
end
end
View
11 spec/pomodoro_spec.rb
@@ -60,7 +60,7 @@ def Pomodoro.work_growl
Pomodoro.start!
Pomodoro.should_not_receive(:stop!)
Timecop.travel(Chronic.parse('24 minutes from now'))
- Pomodoro.work(0)
+ Pomodoro.work
Timecop.return
end
@@ -68,7 +68,7 @@ def Pomodoro.work_growl
Pomodoro.start!
Pomodoro.should_receive(:stop!)
Timecop.travel(Chronic.parse('26 minutes from now'))
- Pomodoro.work(0)
+ Pomodoro.work
Timecop.return
end
@@ -76,22 +76,23 @@ def Pomodoro.work_growl
Pomodoro.start!
Pomodoro.should_not_receive(:start!)
Timecop.travel(Chronic.parse('29 minutes from now'))
- Pomodoro.work(0)
+ Pomodoro.work
Timecop.return
end
it "calls #start! after 30 minutes" do
Pomodoro.start!
Pomodoro.should_receive(:start!)
+ Pomodoro.instance_variable_set(:@stopped, true)
Timecop.travel(Chronic.parse('31 minutes from now'))
- Pomodoro.work(0)
+ Pomodoro.work
Timecop.return
end
it "sets @start_time if it's not set" do
Pomodoro.instance_variable_set(:@start_time, nil)
Timecop.freeze do
- Pomodoro.work(0)
+ Pomodoro.work
Pomodoro.instance_variable_get(:@start_time).should == Time.now
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.