wires-inotify 0.0.0 → 0.9.0
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.
- checksums.yaml +4 -4
- data/lib/wires/inotify.rb +166 -0
- metadata +22 -8
- data/lib/wires-inotify.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb199f81f59733bfb394ffc5e661cf0a5a10644a
|
4
|
+
data.tar.gz: 4fc657e5e03df97fb2aa6cf195114dede637dd71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e823a8f3d3525a9dcfd02b78a4deaa295d755aab567d85ec0b94524e294d281ecee8cb4755dec067daedf2c54a11dd530a40fb9d6c7570b2ded4c5b4f03626bb
|
7
|
+
data.tar.gz: e4ef111babbf2e1642de9dc73901add6ba0659dacb1e89ef33446e27f400b231e93faef9fb037b37f69e583eebe259b9d4889a6979707aa701c77e27945502f8
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'wires'
|
2
|
+
require 'rb-inotify'
|
3
|
+
|
4
|
+
def inotify_watch(path, *flags)
|
5
|
+
Wires::NotifyHub.watch(path, *flags)
|
6
|
+
end
|
7
|
+
|
8
|
+
def inotify_on(flags, channels='*', &codeblock)
|
9
|
+
flags = [flags] unless flags.is_a? Array
|
10
|
+
channels = [channels] unless channels.is_a? Array
|
11
|
+
for channel in channels
|
12
|
+
Wires::NotifyHub.watch(channel, *flags)
|
13
|
+
events = flags.map!{|x| ("notify_"+x.to_s).to_sym}
|
14
|
+
.map!{|x| x==:notify_all_events ? :notify : x }
|
15
|
+
Wires::Channel.new(channel).register(events, codeblock)
|
16
|
+
end
|
17
|
+
nil end
|
18
|
+
|
19
|
+
module Wires
|
20
|
+
|
21
|
+
class NotifyEvent < Event; end
|
22
|
+
|
23
|
+
class NotifyAccessEvent < NotifyEvent; end
|
24
|
+
class NotifyAttribEvent < NotifyEvent; end
|
25
|
+
class NotifyModifyEvent < NotifyEvent; end
|
26
|
+
class NotifyOpenEvent < NotifyEvent; end
|
27
|
+
class NotifyCreateEvent < NotifyEvent; end
|
28
|
+
class NotifyDeleteEvent < NotifyEvent; end
|
29
|
+
class NotifyDeleteSelfEvent < NotifyEvent; end
|
30
|
+
class NotifyMoveSelfEvent < NotifyEvent; end
|
31
|
+
class NotifyIgnoredEvent < NotifyEvent; end
|
32
|
+
|
33
|
+
class NotifyCloseEvent < NotifyEvent; end
|
34
|
+
class NotifyCloseWriteEvent < NotifyCloseEvent; end
|
35
|
+
class NotifyCloseNowriteEvent < NotifyCloseEvent; end
|
36
|
+
|
37
|
+
class NotifyMoveEvent < NotifyEvent; end
|
38
|
+
class NotifyMovedFromEvent < NotifyMoveEvent; end
|
39
|
+
class NotifyMovedToEvent < NotifyMoveEvent; end
|
40
|
+
|
41
|
+
class NotifyHub
|
42
|
+
|
43
|
+
class << self
|
44
|
+
|
45
|
+
attr_accessor :notifier
|
46
|
+
attr_reader :state
|
47
|
+
def alive?; @state==:alive end
|
48
|
+
def dead?; @state==:dead end
|
49
|
+
|
50
|
+
def class_init
|
51
|
+
|
52
|
+
# @@events_init = EventRegistry.list.select{ |x| (x < NotifyEvent) }
|
53
|
+
@@events = Hash.new
|
54
|
+
EventRegistry.list.select{ |x| (x < NotifyEvent) }.each do |cls|
|
55
|
+
@@events[cls.codestring.gsub(/^notify_/, "").to_sym] = cls
|
56
|
+
end
|
57
|
+
|
58
|
+
@state = :dead
|
59
|
+
@notifier = INotify::Notifier.new
|
60
|
+
|
61
|
+
Hub.after_run(retain:true) do
|
62
|
+
@state = :alive
|
63
|
+
@thread = Thread.new { while alive?; thread_iter; Thread.pass; end }
|
64
|
+
end
|
65
|
+
|
66
|
+
Hub.before_kill(retain:true) do
|
67
|
+
@state = :dead
|
68
|
+
@thread.kill
|
69
|
+
@thread = nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def watch(path, *flags, &block)
|
74
|
+
flags << :all_events if (flags & @@events.keys).empty?
|
75
|
+
inject_a_watcher(@notifier.watch(path, *flags, &block))
|
76
|
+
end
|
77
|
+
|
78
|
+
def list
|
79
|
+
@notifier.watchers.values
|
80
|
+
.map { |w| inject_a_watcher(w)} # Inject new methods into obj
|
81
|
+
.reject { |w| w.closed? } # Exclude closed watchers from list
|
82
|
+
end
|
83
|
+
|
84
|
+
def matching(path=/.*/, *flags)
|
85
|
+
list.select { |w| (path.is_a?(Regexp)) ?
|
86
|
+
(path=~w.path) :
|
87
|
+
(path.to_s==w.path) }
|
88
|
+
.reject { |w| flags.detect{ |f| not flag_match(f, w.flags) } }
|
89
|
+
end
|
90
|
+
|
91
|
+
# Close all watchers and returns number of watchers closed
|
92
|
+
def close_all
|
93
|
+
s = list.size
|
94
|
+
list.each { |w| w.close }
|
95
|
+
s>0 ? s : nil
|
96
|
+
end
|
97
|
+
|
98
|
+
# Close watchers matching args and returns number of watchers closed
|
99
|
+
def close_matching(*args) # :args: path=/.*/, *flags
|
100
|
+
matches = matching(*args)
|
101
|
+
matches.each { |w| w.close }
|
102
|
+
(s=matches.size)>0 ? s : nil
|
103
|
+
end
|
104
|
+
|
105
|
+
threadlock (public_methods-superclass.public_methods)
|
106
|
+
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
# Determine if flag is implied (or explied) by flags array
|
111
|
+
def flag_match(testflag, flags)
|
112
|
+
return true if flags.include? :all_events
|
113
|
+
|
114
|
+
!!flags.detect{ |f| testflag==f or
|
115
|
+
(@@events[testflag] and
|
116
|
+
@@events[f] and
|
117
|
+
@@events[testflag]<=@@events[f]) }
|
118
|
+
end
|
119
|
+
|
120
|
+
# Open metaclass of w to add close state tracking and return obj
|
121
|
+
def inject_a_watcher(watcher)
|
122
|
+
return watcher if watcher.public_methods.include? :closed?
|
123
|
+
|
124
|
+
watcher.instance_variable_set(:@closed, false)
|
125
|
+
class << watcher
|
126
|
+
alias :_old_close :close
|
127
|
+
def close(*args)
|
128
|
+
self.instance_variable_set(:@closed, true)
|
129
|
+
begin; _old_close(*args)
|
130
|
+
rescue SystemCallError; end # If error, assume already closed
|
131
|
+
end
|
132
|
+
def closed?; self.instance_variable_get(:@closed); end
|
133
|
+
end
|
134
|
+
|
135
|
+
watcher
|
136
|
+
end
|
137
|
+
|
138
|
+
# Called repeatedly in inotify event processing thread
|
139
|
+
def thread_iter
|
140
|
+
@notifier.read_events.each { |e| process_event(e); e.callback! }
|
141
|
+
end
|
142
|
+
|
143
|
+
# Fire a wires event for inotify event e
|
144
|
+
def process_event(e)
|
145
|
+
return if dead?
|
146
|
+
|
147
|
+
if (common_flags = (e.flags & @@events.keys)).empty?
|
148
|
+
raise NotImplementedError, \
|
149
|
+
"No Wires::NotifyEvent for flags #{e.flags}"
|
150
|
+
end
|
151
|
+
|
152
|
+
cls = Event.from_codestring("notify_"+common_flags.first.to_s)
|
153
|
+
|
154
|
+
Channel.new(e.watcher.path)
|
155
|
+
.fire(cls.new(*e.flags,
|
156
|
+
name: e.name,
|
157
|
+
absolute_name: e.absolute_name,
|
158
|
+
watchpath: e.watcher.path))
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
class_init
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wires-inotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wires
|
@@ -25,13 +25,27 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.2.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rb-inotify
|
28
|
+
name: rb-inotify
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - '>='
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
|
-
type: :
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - '>='
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: turn
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - '>='
|
@@ -66,13 +80,13 @@ dependencies:
|
|
66
80
|
- - '>='
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
|
-
description: Wires extension gem to integrate with inotify.
|
83
|
+
description: Wires extension gem to integrate with inotify via rb-inotify.
|
70
84
|
email: joe.eli.mac@gmail.com
|
71
85
|
executables: []
|
72
86
|
extensions: []
|
73
87
|
extra_rdoc_files: []
|
74
88
|
files:
|
75
|
-
- lib/wires
|
89
|
+
- lib/wires/inotify.rb
|
76
90
|
homepage: https://github.com/jemc/wires-inotify/
|
77
91
|
licenses:
|
78
92
|
- 'Copyright (c) Joe McIlvain. All rights reserved '
|