Skip to content

Commit

Permalink
Made the inclusion of 'rev' completely optional for both using the
Browse files Browse the repository at this point in the history
watchr gem and developing the watchr gem.
  • Loading branch information
TwP authored and mynyml committed Sep 29, 2009
1 parent e16650b commit 1478d72
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
14 changes: 10 additions & 4 deletions lib/watchr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
# See README for more details
#
module Watchr
begin
require 'rev'
HAVE_REV = true
rescue LoadError, RuntimeError
HAVE_REV = false
end

autoload :Script, 'watchr/script'
autoload :Controller, 'watchr/controller'

module EventHandler
autoload :Base, 'watchr/event_handlers/base'
autoload :Unix, 'watchr/event_handlers/unix'
autoload :Unix, 'watchr/event_handlers/unix' if ::Watchr::HAVE_REV
autoload :Portable, 'watchr/event_handlers/portable'
end

Expand Down Expand Up @@ -92,10 +99,9 @@ def handler
when /mswin|windows|cygwin/i
Watchr::EventHandler::Portable
when /sunos|solaris|darwin|mach|osx|bsd|linux/i, 'unix'
begin
require 'rev'
if ::Watchr::HAVE_REV
Watchr::EventHandler::Unix
rescue LoadError, RuntimeError
else
Watchr.debug "rev not found. `gem install rev` to get evented handler"
Watchr::EventHandler::Portable
end
Expand Down
2 changes: 0 additions & 2 deletions lib/watchr/event_handlers/unix.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'rev'

module Watchr
module EventHandler
class Unix
Expand Down
4 changes: 4 additions & 0 deletions test/event_handlers/test_unix.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if Watchr::HAVE_REV

require 'test/test_helper'

class UnixEventHandlerTest < Test::Unit::TestCase
Expand Down Expand Up @@ -54,3 +56,5 @@ def teardown
@loop.watchers.every.path.should exclude('bar')
end
end

end # if Watchr::HAVE_REV
8 changes: 4 additions & 4 deletions test/test_watchr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def setup

Watchr.handler = nil
ENV['HANDLER'] = 'linux'
Watchr.handler.should be(Watchr::EventHandler::Unix)
Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)

Watchr.handler = nil
ENV['HANDLER'] = 'bsd'
Watchr.handler.should be(Watchr::EventHandler::Unix)
Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)

Watchr.handler = nil
ENV['HANDLER'] = 'darwin'
Watchr.handler.should be(Watchr::EventHandler::Unix)
Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)

Watchr.handler = nil
ENV['HANDLER'] = 'unix'
Watchr.handler.should be(Watchr::EventHandler::Unix)
Watchr.handler.should be(Watchr::HAVE_REV ? Watchr::EventHandler::Unix : Watchr::EventHandler::Portable)

Watchr.handler = nil
ENV['HANDLER'] = 'mswin'
Expand Down

0 comments on commit 1478d72

Please sign in to comment.