em-dir-watcher 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/examples/monitor.rb +18 -0
- data/lib/em-dir-watcher/platform/nix.rb +105 -0
- data/lib/em-dir-watcher.rb +21 -0
- data/test/helper.rb +10 -0
- data/test/test_em-dir-watcher.rb +7 -0
- metadata +75 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Andrey Tarantsov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
em-dir-watcher: real directory monitoring for EventMachine
|
2
|
+
==========================================================
|
3
|
+
|
4
|
+
Employs FSEvents, inotify or Win32 Directory Change Notifications APIs under EventMachine. (Forks a subprocess for blocking watchers.)
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'em-dir-watcher'
|
11
|
+
|
12
|
+
EM.run {
|
13
|
+
dw = EMDirWatcher.watch '.', ['**/*.css', 'lib/**/*.rb'] do |path|
|
14
|
+
if File.exists? path
|
15
|
+
puts "Modified: #{path}"
|
16
|
+
else
|
17
|
+
puts "Deleted: #{path}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
puts "EventMachine running..."
|
21
|
+
}
|
22
|
+
|
23
|
+
Run `examples/monitor.rb` to see it in action.
|
24
|
+
|
25
|
+
License
|
26
|
+
-------
|
27
|
+
|
28
|
+
Copyright (c) 2010 Andrey Tarantsov. Distributed under the MIT license. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "em-dir-watcher"
|
8
|
+
gem.summary = %Q{Directory watching support for EventMachine (fssm / win32-changenotify)}
|
9
|
+
gem.description = gem.summary
|
10
|
+
gem.email = "andreyvit@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/mockko/em-dir-watcher"
|
12
|
+
gem.authors = ["Andrey Tarantsov"]
|
13
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "em-dir-watcher #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/examples/monitor.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'em-dir-watcher'
|
5
|
+
|
6
|
+
dir = (ARGV.empty? ? '.' : ARGV.shift)
|
7
|
+
globs = (ARGV.empty? ? ['**/*'] : ARGV)
|
8
|
+
|
9
|
+
EM.run {
|
10
|
+
dw = EMDirWatcher.watch dir, globs do |path|
|
11
|
+
if File.exists? path
|
12
|
+
puts "Modified: #{path}"
|
13
|
+
else
|
14
|
+
puts "Deleted: #{path}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts "Monitoring #{File.expand_path(dir)}..."
|
18
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
|
2
|
+
module EMDirWatcher
|
3
|
+
module Platform
|
4
|
+
module NIX
|
5
|
+
|
6
|
+
# monkey-patch to set latency to 0
|
7
|
+
module FssmFSEventsMonkeyPatch
|
8
|
+
def patched_add_handler(handler, preload=true)
|
9
|
+
@handlers[handler.path.to_s] = handler
|
10
|
+
|
11
|
+
fsevent = Rucola::FSEvents.new(handler.path.to_s, {:latency => 0.0}) do |events|
|
12
|
+
events.each do |event|
|
13
|
+
handler.refresh(event.path)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
fsevent.create_stream
|
18
|
+
handler.refresh(nil, true) if preload
|
19
|
+
fsevent.start
|
20
|
+
@fsevents << fsevent
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Watcher
|
25
|
+
|
26
|
+
attr_accessor :handler, :active
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def run_fssm_watcher path, globs
|
30
|
+
require 'fssm'
|
31
|
+
FSSM::Backends::FSEvents.send(:include, FssmFSEventsMonkeyPatch)
|
32
|
+
FSSM::Backends::FSEvents.send(:alias_method, :add_handler, :patched_add_handler)
|
33
|
+
$stdout.sync = true
|
34
|
+
report = proc { |b,r|
|
35
|
+
puts File.join(b, r)
|
36
|
+
}
|
37
|
+
FSSM.monitor path, globs do
|
38
|
+
create &report
|
39
|
+
delete &report
|
40
|
+
update &report
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize path, globs, &handler
|
46
|
+
@path = path
|
47
|
+
@globs = globs
|
48
|
+
@handler = handler
|
49
|
+
@active = true
|
50
|
+
|
51
|
+
setup_listener
|
52
|
+
end
|
53
|
+
|
54
|
+
def stop
|
55
|
+
@active = false
|
56
|
+
kill
|
57
|
+
end
|
58
|
+
|
59
|
+
def kill
|
60
|
+
if @io
|
61
|
+
Process.kill 'TERM', @io.pid
|
62
|
+
Process.waitpid @io.pid
|
63
|
+
@io = nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def setup_listener
|
68
|
+
io = open('|-', 'r')
|
69
|
+
if io.nil?
|
70
|
+
Watcher.run_fssm_watcher @path, @globs
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
@io = io
|
74
|
+
|
75
|
+
@connection = EM.watch io do |conn|
|
76
|
+
class << conn
|
77
|
+
attr_accessor :watcher
|
78
|
+
|
79
|
+
def notify_readable
|
80
|
+
path = @io.readline.strip
|
81
|
+
@watcher.handler.call path
|
82
|
+
rescue EOFError
|
83
|
+
detach
|
84
|
+
@watcher.kill # waitpid to cleanup zombie
|
85
|
+
if @watcher.active
|
86
|
+
EM.next_tick do
|
87
|
+
@watcher.setup_listener
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def unbind
|
93
|
+
@watcher.kill
|
94
|
+
end
|
95
|
+
end
|
96
|
+
conn.watcher = self
|
97
|
+
conn.notify_readable = true
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
require 'eventmachine'
|
3
|
+
require 'rbconfig'
|
4
|
+
|
5
|
+
module EMDirWatcher
|
6
|
+
PLATFORM =
|
7
|
+
case Config::CONFIG['target_os']
|
8
|
+
when /mswin|mingw/ then 'Windows'
|
9
|
+
else 'NIX'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require "em-dir-watcher/platform/#{EMDirWatcher::PLATFORM.upcase}"
|
14
|
+
|
15
|
+
module EMDirWatcher
|
16
|
+
Watcher = Platform.const_get(PLATFORM)::Watcher
|
17
|
+
|
18
|
+
def self.watch path, globs, &handler
|
19
|
+
Watcher.new path, globs, &handler
|
20
|
+
end
|
21
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-dir-watcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Andrey Tarantsov
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-17 00:00:00 +07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Directory watching support for EventMachine (fssm / win32-changenotify)
|
22
|
+
email: andreyvit@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.md
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- examples/monitor.rb
|
38
|
+
- lib/em-dir-watcher.rb
|
39
|
+
- lib/em-dir-watcher/platform/nix.rb
|
40
|
+
- test/helper.rb
|
41
|
+
- test/test_em-dir-watcher.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/mockko/em-dir-watcher
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.6
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: Directory watching support for EventMachine (fssm / win32-changenotify)
|
72
|
+
test_files:
|
73
|
+
- test/helper.rb
|
74
|
+
- test/test_em-dir-watcher.rb
|
75
|
+
- examples/monitor.rb
|