rb-inotify 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  /.yardoc
2
2
  /doc
3
+ /pkg
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -3,14 +3,12 @@ module INotify
3
3
  # Each {Watcher} can fire many events,
4
4
  # which are passed to that watcher's callback.
5
5
  class Event
6
- # An integer specifying that this event is related to some other event,
7
- # which will have the same cookie.
8
- #
9
- # Currently, this is only used for files that are moved within the same directory.
10
- # Both the `:moved_from` and the `:moved_to` events will have the same cookie.
6
+ # A list of other events that are related to this one.
7
+ # Currently, this is only used for files that are moved within the same directory:
8
+ # the `:moved_from` and the `:moved_to` events will be related.
11
9
  #
12
- # @return [Fixnum]
13
- attr_reader :cookie
10
+ # @return [Array<Event>]
11
+ attr_reader :related
14
12
 
15
13
  # The name of the file that the event occurred on.
16
14
  # This is only set for events that occur on files in directories;
@@ -24,6 +22,16 @@ module INotify
24
22
  # @return [Notifier]
25
23
  attr_reader :notifier
26
24
 
25
+ # An integer specifying that this event is related to some other event,
26
+ # which will have the same cookie.
27
+ #
28
+ # Currently, this is only used for files that are moved within the same directory.
29
+ # Both the `:moved_from` and the `:moved_to` events will have the same cookie.
30
+ #
31
+ # @private
32
+ # @return [Fixnum]
33
+ attr_reader :cookie
34
+
27
35
  # The {Watcher#id id} of the {Watcher} that fired this event.
28
36
  #
29
37
  # @private
@@ -80,6 +88,7 @@ module INotify
80
88
  def initialize(data, notifier)
81
89
  ptr = FFI::MemoryPointer.from_string(data)
82
90
  @native = Native::Event.new(ptr)
91
+ @related = []
83
92
  @cookie = @native[:cookie]
84
93
  @name = data[@native.size, @native[:len]].gsub(/\0+$/, '')
85
94
  @notifier = notifier
@@ -152,7 +152,15 @@ module INotify
152
152
  #
153
153
  # @see #process
154
154
  def run
155
- loop {process}
155
+ @stop = false
156
+ process until @stop || closed?
157
+ end
158
+
159
+ # Stop watching for filesystem events.
160
+ # That is, if we're in a \{#run} loop,
161
+ # exit out as soon as we finish handling the events.
162
+ def stop
163
+ @stop = true
156
164
  end
157
165
 
158
166
  # Blocks until there are one or more filesystem events
@@ -186,9 +194,14 @@ module INotify
186
194
  end
187
195
 
188
196
  events = []
197
+ cookies = {}
189
198
  while ev = Event.consume(data, self)
190
199
  events << ev
200
+ next if ev.cookie == 0
201
+ cookies[ev.cookie] ||= []
202
+ cookies[ev.cookie] << ev
191
203
  end
204
+ cookies.each {|c, evs| evs.each {|ev| ev.related.replace(evs - [ev]).freeze}}
192
205
  events
193
206
  end
194
207
  end
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rb-inotify}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nathan Weizenbaum"]
12
+ s.date = %q{2009-11-29}
13
+ s.description = %q{A Ruby wrapper for Linux's inotify, using FFI}
14
+ s.email = %q{nex342@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ ".yardopts",
21
+ "MIT-LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/rb-inotify.rb",
26
+ "lib/rb-inotify/event.rb",
27
+ "lib/rb-inotify/native.rb",
28
+ "lib/rb-inotify/native/flags.rb",
29
+ "lib/rb-inotify/notifier.rb",
30
+ "lib/rb-inotify/watcher.rb",
31
+ "rb-inotify.gemspec"
32
+ ]
33
+ s.homepage = %q{http://github.com/nex3/rb-notify}
34
+ s.rdoc_options = ["--charset=UTF-8"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.3.5}
37
+ s.summary = %q{A Ruby wrapper for Linux's inotify, using FFI}
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<yard>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<yard>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<yard>, [">= 0"])
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-inotify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -43,6 +43,7 @@ files:
43
43
  - lib/rb-inotify/native/flags.rb
44
44
  - lib/rb-inotify/notifier.rb
45
45
  - lib/rb-inotify/watcher.rb
46
+ - rb-inotify.gemspec
46
47
  has_rdoc: true
47
48
  homepage: http://github.com/nex3/rb-notify
48
49
  licenses: []