Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Quick cleanup

  • Loading branch information...
commit c220ae1fc126269cd9fe7eac8441729450786011 1 parent 7264ae2
mynyml authored
23 lib/watchr.rb
View
@@ -17,7 +17,6 @@ module Watchr
VERSION = '0.6'
begin
- begin require 'rubygems'; rescue LoadError; end
require 'fsevent'
HAVE_FSE = true
rescue LoadError, RuntimeError
@@ -36,10 +35,9 @@ module Watchr
module EventHandler
autoload :Base, 'watchr/event_handlers/base'
- autoload :Unix, 'watchr/event_handlers/unix' if ::Watchr::HAVE_REV
autoload :Portable, 'watchr/event_handlers/portable'
- #autoload :FSE, 'watchr/event_handlers/fse' if ::Watchr::HAVE_FSE
- autoload :FSE, 'watchr/event_handlers/darwin' if ::Watchr::HAVE_FSE
+ autoload :Unix, 'watchr/event_handlers/unix' if ::Watchr::HAVE_REV
+ autoload :FSE, 'watchr/event_handlers/darwin' if ::Watchr::HAVE_FSE
end
class << self
@@ -110,18 +108,23 @@ def debug(msg)
#
def handler
@handler ||=
- case check_handler = ENV['HANDLER'] || Config::CONFIG['host_os']
- when /mswin|windows|cygwin/i
- Watchr::EventHandler::Portable
- when /sunos|solaris|darwin|mach|osx|bsd|linux/i, 'unix'
- if ::Watchr::HAVE_FSE && check_handler =~ /osx|darwin/
+ case ENV['HANDLER'] || Config::CONFIG['host_os']
+ when /darwin|mach|osx|fsevents?/i
+ if Watchr::HAVE_FSE
Watchr::EventHandler::FSE
- elsif ::Watchr::HAVE_REV
+ else
+ Watchr.debug "fsevent not found. `gem install ruby-fsevent` to get evented handler"
+ Watchr::EventHandler::Portable
+ end
+ when /sunos|solaris|bsd|linux|unix/i
+ if Watchr::HAVE_REV
Watchr::EventHandler::Unix
else
Watchr.debug "rev not found. `gem install rev` to get evented handler"
Watchr::EventHandler::Portable
end
+ when /mswin|windows|cygwin/i
+ Watchr::EventHandler::Portable
else
Watchr::EventHandler::Portable
end
4 test/event_handlers/test_darwin.rb
View
@@ -1,6 +1,6 @@
require 'test/test_helper'
-if Watchr::HAVE_REV
+if Watchr::HAVE_FSE
class Watchr::EventHandler::Unix::SingleFileWatcher
public :type
@@ -159,4 +159,4 @@ def trigger_event(watcher, now, *types)
end
end
-end # if Watchr::HAVE_REV
+end # if Watchr::HAVE_FSE
18 test/test_watchr.rb
View
@@ -35,12 +35,24 @@ def setup
assert_equal Watchr::EventHandler::Unix, Watchr.handler
Watchr.handler = nil
- ENV['HANDLER'] = 'darwin'
+ ENV['HANDLER'] = 'unix'
assert_equal Watchr::EventHandler::Unix, Watchr.handler
+ end
+
+ if Watchr::HAVE_FSE
+
Watchr.handler = nil
- ENV['HANDLER'] = 'unix'
- assert_equal Watchr::EventHandler::Unix, Watchr.handler
+ ENV['HANDLER'] = 'darwin'
+ assert_equal Watchr::EventHandler::FSE, Watchr.handler
+
+ Watchr.handler = nil
+ ENV['HANDLER'] = 'osx'
+ assert_equal Watchr::EventHandler::FSE, Watchr.handler
+
+ Watchr.handler = nil
+ ENV['HANDLER'] = 'fsevent'
+ assert_equal Watchr::EventHandler::FSE, Watchr.handler
end
Please sign in to comment.
Something went wrong with that request. Please try again.