Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Turning into a skinny daemon, and saving time.

  • Loading branch information...
commit 118fadb4006fb030d207f65a0364bac8e2b1c9e3 1 parent 9f7d5c1
@steveklabnik authored
View
1  Gemfile
@@ -6,4 +6,5 @@ gemspec
group :test do
gem "rspec", "~>2.1.0"
gem "autotest"
+ gem "timecop"
end
View
17 Gemfile.lock
@@ -3,13 +3,18 @@ PATH
specs:
pomodoro (0.0.1)
noprocrast
+ sinatra
+ thin
GEM
remote: http://rubygems.org/
specs:
autotest (4.4.5)
+ daemons (1.1.0)
diff-lcs (1.1.2)
+ eventmachine (0.12.10)
noprocrast (0.1.6)
+ rack (1.2.1)
rspec (2.1.0)
rspec-core (~> 2.1.0)
rspec-expectations (~> 2.1.0)
@@ -18,6 +23,15 @@ GEM
rspec-expectations (2.1.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.1.0)
+ sinatra (1.1.0)
+ rack (~> 1.1)
+ tilt (~> 1.1)
+ thin (1.2.7)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+ tilt (1.1)
+ timecop (0.3.5)
PLATFORMS
ruby
@@ -27,3 +41,6 @@ DEPENDENCIES
noprocrast
pomodoro!
rspec (~> 2.1.0)
+ sinatra
+ thin
+ timecop
View
19 bin/pomodoro
@@ -1,13 +1,12 @@
#!/usr/bin/env ruby
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-require 'pomodoro'
+require './lib/pomodoro'
+require 'thin'
-case ARGV[0]
-when /^start$/
- Pomodoro.start!
-when /^stop$/
- Pomodoro.stop!
-else
- puts "USAGE: pomodoro {start|stop}"
-end
+rackup_file = "./lib/pomodoro/config.ru"
+
+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
15 lib/pomodoro.rb
@@ -1,11 +1,24 @@
+require "rubygems"
+require "bundler/setup"
+require 'sinatra'
+require 'noprocrast'
+
module Pomodoro
class << self
def start!
Noprocrast.activate!
+ @start_time = Time.now
end
-
def stop!
Noprocrast.deactivate!
end
end
end
+
+class PomodoroServer < Sinatra::Base
+
+ get "/" do
+ "GET BACK TO WORK"
+ end
+
+end
View
3  lib/pomodoro/config.ru
@@ -0,0 +1,3 @@
+require "pomodoro"
+Pomodoro.start!
+PomodoroServer.run! :port => 80
View
2  pomodoro.gemspec
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency("noprocrast")
+ s.add_dependency("thin")
+ s.add_dependency("sinatra")
end
View
17 spec/pomodoro_spec.rb
@@ -1,8 +1,16 @@
-require 'pomodoro'
+# I'm not sure why these don't work, since they're in the spec_helper...
require 'noprocrast'
+require './lib/pomodoro'
+require 'timecop'
describe Pomodoro do
+ before :all do
+ #rspec2 hates me, and won't stub properly
+ #Noprocrast.stub(:activate!)
+ #Noprocrast.stub(:deactivate!)
+ end
+
describe "#start!" do
it "uses noprocrast" do
@@ -10,6 +18,13 @@
Pomodoro.start!
end
+ it "saves its start time" do
+ Noprocrast.should_receive(:activate!)
+ Timecop.freeze
+ Pomodoro.start!
+ Pomodoro.instance_variable_get(:@start_time).should == Time.now
+ end
+
end
describe "#stop!" do
View
2  spec/spec_helper.rb
@@ -1,5 +1,5 @@
require 'rspec'
-require 'pomodoro'
+require '../lib/pomodoro'
RSpec.configure do |c|
c.fail_fast = true #this is awesome
Please sign in to comment.
Something went wrong with that request. Please try again.