Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Commit

Permalink
Turning into a skinny daemon, and saving time.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Nov 28, 2010
1 parent 9f7d5c1 commit 118fadb
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ gemspec
group :test do
gem "rspec", "~>2.1.0"
gem "autotest"
gem "timecop"
end
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -27,3 +41,6 @@ DEPENDENCIES
noprocrast
pomodoro!
rspec (~> 2.1.0)
sinatra
thin
timecop
19 changes: 9 additions & 10 deletions bin/pomodoro
Original file line number Diff line number Diff line change
@@ -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!
15 changes: 14 additions & 1 deletion lib/pomodoro.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/pomodoro/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "pomodoro"
Pomodoro.start!
PomodoroServer.run! :port => 80
2 changes: 2 additions & 0 deletions pomodoro.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion spec/pomodoro_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
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
Noprocrast.should_receive(:activate!)
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
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rspec'
require 'pomodoro'
require '../lib/pomodoro'

RSpec.configure do |c|
c.fail_fast = true #this is awesome
Expand Down

0 comments on commit 118fadb

Please sign in to comment.