rb-fsevent 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +34 -0
- data/bin/rb-fsevent +72 -0
- data/lib/rb-fsevent.rb +1 -0
- data/lib/rb-fsevent/fsevent.rb +40 -0
- data/lib/rb-fsevent/version.rb +3 -0
- metadata +136 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Thibaud Guillaume-Gentil
|
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.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= rb-fsevent
|
2
|
+
|
3
|
+
Very simple & usable Mac OSX FSEvents API
|
4
|
+
|
5
|
+
- No compilation needed (FFI)
|
6
|
+
- RubyCocoa not required!
|
7
|
+
- Signals are working
|
8
|
+
- Tested on Ruby 1.8.7 & 1.9.2
|
9
|
+
|
10
|
+
== Install
|
11
|
+
|
12
|
+
gem install rb-fsevent
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
require 'rb-fsevent'
|
17
|
+
|
18
|
+
fsevent = FSEvent.new
|
19
|
+
fsevent.watch Dir.pwd do |directories|
|
20
|
+
puts "Detected change inside: #{directories.inspect}"
|
21
|
+
end
|
22
|
+
fsevent.run
|
23
|
+
|
24
|
+
== Development
|
25
|
+
|
26
|
+
- Source hosted at {GitHub}[http://github.com/thibaudgg/rb-fsevent]
|
27
|
+
- Report issues/Questions/Feature requests on {GitHub Issues}[http://github.com/thibaudgg/rb-fsevent/issues]
|
28
|
+
|
29
|
+
Pull requests are very welcome! Make sure your patches are well tested. Please create a topic branch for every separate change
|
30
|
+
you make.
|
31
|
+
|
32
|
+
== Authors
|
33
|
+
|
34
|
+
{Thibaud Guillaume-Gentil}[http://github.com/thibaudgg]
|
data/bin/rb-fsevent
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'ffi'
|
4
|
+
|
5
|
+
paths, latency = ARGV[0].split(','), ARGV[1].to_f
|
6
|
+
|
7
|
+
module CarbonCore
|
8
|
+
extend FFI::Library
|
9
|
+
ffi_lib '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Versions/Current/CarbonCore'
|
10
|
+
|
11
|
+
attach_function :CFStringCreateWithCString, [:pointer, :string, :int], :pointer
|
12
|
+
KCFStringEncodingUTF8 = 0x08000100
|
13
|
+
attach_function :CFStringGetLength, [:pointer, :pointer, :int, :pointer, :pointer, :pointer], :int
|
14
|
+
|
15
|
+
attach_function :CFArrayCreate, [:pointer, :pointer, :int, :pointer], :pointer
|
16
|
+
|
17
|
+
attach_function :CFRunLoopRun, :CFRunLoopRun, [], :void
|
18
|
+
attach_function :CFRunLoopGetCurrent, [], :pointer
|
19
|
+
attach_variable :kCFRunLoopDefaultMode, :pointer
|
20
|
+
|
21
|
+
callback :FSEventStreamCallback, [:pointer, :pointer, :int, :pointer, :pointer, :pointer], :void
|
22
|
+
|
23
|
+
KFSEventStreamEventIdSinceNow = -1
|
24
|
+
attach_function :FSEventStreamCreate, [:pointer, :FSEventStreamCallback, :pointer, :pointer, :long, :double, :int], :pointer
|
25
|
+
attach_function :FSEventStreamScheduleWithRunLoop, [:pointer, :pointer, :pointer], :void
|
26
|
+
attach_function :FSEventStreamStart, [:pointer], :void
|
27
|
+
attach_function :FSEventStreamStop, [:pointer], :void
|
28
|
+
end
|
29
|
+
|
30
|
+
class FSEventStream
|
31
|
+
KFSEventStreamEventFlagMustScanSubDirs = 0x1
|
32
|
+
|
33
|
+
class StreamError < StandardError;
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_accessor :stream
|
37
|
+
|
38
|
+
def initialize(paths, latency)
|
39
|
+
# Create array of paths to observe
|
40
|
+
paths_ptr = FFI::MemoryPointer.new(:pointer)
|
41
|
+
paths.each do |path|
|
42
|
+
path_cfstring = CarbonCore.CFStringCreateWithCString(nil, path, CarbonCore::KCFStringEncodingUTF8)
|
43
|
+
paths_ptr.write_pointer(path_cfstring)
|
44
|
+
end
|
45
|
+
paths_cfarray = CarbonCore.CFArrayCreate nil, paths_ptr, 1, nil
|
46
|
+
|
47
|
+
# Create callback
|
48
|
+
callback = lambda do |stream, client_callback_info, number_of_events, event_paths, event_flags, event_ids|
|
49
|
+
if number_of_events > 0
|
50
|
+
paths = event_paths.get_array_of_string(0, number_of_events)
|
51
|
+
$stdout.puts paths.join(" ")
|
52
|
+
$stdout.flush
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
@stream = CarbonCore.FSEventStreamCreate(nil, callback, nil, paths_cfarray, CarbonCore::KFSEventStreamEventIdSinceNow, latency, 0)
|
57
|
+
|
58
|
+
CarbonCore.FSEventStreamScheduleWithRunLoop(stream, CarbonCore.CFRunLoopGetCurrent, CarbonCore.kCFRunLoopDefaultMode)
|
59
|
+
CarbonCore.FSEventStreamStart(stream)
|
60
|
+
end
|
61
|
+
|
62
|
+
def run_loop
|
63
|
+
CarbonCore.CFRunLoopRun
|
64
|
+
end
|
65
|
+
|
66
|
+
def stop
|
67
|
+
CarbonCore.FSEventStreamStop(stream)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
stream = FSEventStream.new(paths, latency)
|
72
|
+
stream.run_loop
|
data/lib/rb-fsevent.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'rb-fsevent/fsevent'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class FSEvent
|
2
|
+
attr_reader :path, :latency, :callback, :pipe
|
3
|
+
|
4
|
+
def watch(path, options = {}, &callback)
|
5
|
+
@path = path
|
6
|
+
@latency = options[:latency] || 0.5
|
7
|
+
@callback = callback
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
launch_bin
|
12
|
+
listen
|
13
|
+
end
|
14
|
+
|
15
|
+
def stop
|
16
|
+
Process.kill("KILL", pipe.pid) if pipe
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def bin_path
|
22
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin'))
|
23
|
+
end
|
24
|
+
|
25
|
+
def launch_bin
|
26
|
+
@pipe = IO.popen("#{bin_path}/rb-fsevent #{path} #{latency}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def listen
|
30
|
+
while !pipe.eof?
|
31
|
+
if line = pipe.readline
|
32
|
+
modified_dir_paths = line.split(" ")
|
33
|
+
callback.call(modified_dir_paths)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue Interrupt
|
37
|
+
stop
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rb-fsevent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thibaud Guillaume-Gentil
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-16 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: ffi
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 6
|
33
|
+
- 3
|
34
|
+
version: 0.6.3
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 19
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
version: 1.0.2
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 15
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 0
|
65
|
+
- 0
|
66
|
+
version: 2.0.0
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
prerelease: false
|
72
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 29
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 1
|
81
|
+
- 3
|
82
|
+
version: 0.1.3
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
85
|
+
description: FSEvents API using FFI (without RubyCocoa)
|
86
|
+
email:
|
87
|
+
- thibaud@thibaud.me
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
extra_rdoc_files: []
|
93
|
+
|
94
|
+
files:
|
95
|
+
- bin/rb-fsevent
|
96
|
+
- lib/rb-fsevent/fsevent.rb
|
97
|
+
- lib/rb-fsevent/version.rb
|
98
|
+
- lib/rb-fsevent.rb
|
99
|
+
- LICENSE
|
100
|
+
- README.rdoc
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://rubygems.org/gems/rb-fsevent
|
103
|
+
licenses: []
|
104
|
+
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
hash: 3
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
version: "0"
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
requirements: []
|
129
|
+
|
130
|
+
rubyforge_project: rb-fsevent
|
131
|
+
rubygems_version: 1.3.7
|
132
|
+
signing_key:
|
133
|
+
specification_version: 3
|
134
|
+
summary: Very simple & usable FSEvents API
|
135
|
+
test_files: []
|
136
|
+
|