directory_watcher 1.4.1 → 1.5.1
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/.gitignore +17 -0
- data/History.txt +10 -0
- data/README.txt +1 -1
- data/Rakefile +16 -5
- data/lib/directory_watcher.rb +166 -139
- data/lib/directory_watcher/collector.rb +283 -0
- data/lib/directory_watcher/configuration.rb +228 -0
- data/lib/directory_watcher/coolio_scanner.rb +61 -127
- data/lib/directory_watcher/em_scanner.rb +81 -153
- data/lib/directory_watcher/event.rb +72 -0
- data/lib/directory_watcher/eventable_scanner.rb +242 -0
- data/lib/directory_watcher/file_stat.rb +65 -0
- data/lib/directory_watcher/logable.rb +26 -0
- data/lib/directory_watcher/notifier.rb +49 -0
- data/lib/directory_watcher/paths.rb +55 -0
- data/lib/directory_watcher/rev_scanner.rb +68 -131
- data/lib/directory_watcher/scan.rb +72 -0
- data/lib/directory_watcher/scan_and_queue.rb +22 -0
- data/lib/directory_watcher/scanner.rb +26 -209
- data/lib/directory_watcher/threaded.rb +277 -0
- data/lib/directory_watcher/version.rb +8 -0
- data/spec/directory_watcher_spec.rb +37 -0
- data/spec/paths_spec.rb +7 -0
- data/spec/scanner_scenarios.rb +236 -0
- data/spec/spec_helper.rb +79 -0
- data/spec/utility_classes.rb +117 -0
- data/version.txt +1 -1
- metadata +123 -23
- data/bin/dw +0 -2
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../../lib/directory_watcher', __FILE__)
|
3
|
+
|
4
|
+
require 'logging'
|
5
|
+
require 'rspec/logging_helper'
|
6
|
+
require 'rspec/autorun'
|
7
|
+
require 'scanner_scenarios'
|
8
|
+
require 'utility_classes'
|
9
|
+
|
10
|
+
include Logging.globally
|
11
|
+
|
12
|
+
#Thread.abort_on_exception = true
|
13
|
+
|
14
|
+
module DirectoryWatcherSpecs::Helpers
|
15
|
+
def scratch_path( *parts )
|
16
|
+
File.join( @scratch_dir, *parts )
|
17
|
+
end
|
18
|
+
|
19
|
+
# NOTE : touch will only work on *nix/BSD style systems
|
20
|
+
# Touch the file with the given timestamp
|
21
|
+
def touch( fname, time = Time.now )
|
22
|
+
stamp = time.strftime("%Y%m%d%H%M.%S")
|
23
|
+
%x[ touch -m -t #{stamp} #{fname} ]
|
24
|
+
end
|
25
|
+
|
26
|
+
def append_to( fname, count = 1 )
|
27
|
+
File.open( fname, "a" ) { |f| count.times { f.puts Time.now }}
|
28
|
+
end
|
29
|
+
|
30
|
+
# create a unique list of numbers with size 'count' and from the range
|
31
|
+
# 0..range
|
32
|
+
def unique_integer_list( count, range )
|
33
|
+
random = (0..range).to_a.sort_by { rand }
|
34
|
+
return random[0,count]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec.configure do |config|
|
39
|
+
config.before(:each) do
|
40
|
+
@spec_dir = DirectoryWatcher.sub_path( "spec" )
|
41
|
+
@scratch_dir = File.join(@spec_dir, "scratch")
|
42
|
+
FileUtils.rm_rf @scratch_dir if File.directory?( @scratch_dir )
|
43
|
+
FileUtils.mkdir @scratch_dir unless File.directory?( @scratch_dir )
|
44
|
+
end
|
45
|
+
|
46
|
+
config.after(:each) do
|
47
|
+
FileUtils.rm_rf @scratch_dir if File.directory?(@scratch_dir)
|
48
|
+
end
|
49
|
+
|
50
|
+
config.include DirectoryWatcherSpecs::Helpers
|
51
|
+
|
52
|
+
include RSpec::LoggingHelper
|
53
|
+
config.capture_log_messages
|
54
|
+
end
|
55
|
+
|
56
|
+
RSpec::Matchers.define :be_events_like do |expected|
|
57
|
+
match do |actual|
|
58
|
+
a = actual.kind_of?( Array ) ?
|
59
|
+
actual.map {|e| [ e.type, File.basename( e.path ) ]} :
|
60
|
+
[ actual.type, File.basename( actual.path ) ]
|
61
|
+
a == expected
|
62
|
+
end
|
63
|
+
|
64
|
+
failure_message_for_should do |actual|
|
65
|
+
s = StringIO.new
|
66
|
+
s.puts [ "Actual".ljust(20), "Expected".ljust(20), "Same?".ljust(20) ].join(" ")
|
67
|
+
s.puts [ "-"*20, "-"*20, "-"*20 ].join(" ")
|
68
|
+
[ actual.size, expected.size ].max.times do |x|
|
69
|
+
a = actual[x]
|
70
|
+
a = a.kind_of?( Array ) ?
|
71
|
+
a.map {|e| [ e.type, File.basename( e.path ) ]} :
|
72
|
+
[ a.type, File.basename( a.path ) ]
|
73
|
+
e = expected[x]
|
74
|
+
r = (a == e) ? "OK" : "Differ"
|
75
|
+
s.puts [ a.inspect.ljust(20), e.inspect.ljust(20), r ].join(" ")
|
76
|
+
end
|
77
|
+
s.string
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module DirectoryWatcherSpecs
|
2
|
+
# EventObserver just hangs out and collects all the events that are sent to it
|
3
|
+
# It is used by the Scenario
|
4
|
+
class EventObserver
|
5
|
+
attr_reader :events
|
6
|
+
attr_reader :logger
|
7
|
+
|
8
|
+
def initialize( logger )
|
9
|
+
@logger = logger
|
10
|
+
@events = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def update( *event_list )
|
14
|
+
logger.debug "got event #{event_list}"
|
15
|
+
@events.concat event_list
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Scenario is a utility to wrap up how to run a directory watcher scenario.
|
20
|
+
# You would use it as such:
|
21
|
+
#
|
22
|
+
# dws = Scenario.new( watcher )
|
23
|
+
# dws.do_after_events(2) do |scenario|
|
24
|
+
# # do something
|
25
|
+
# end.until_events(1)
|
26
|
+
#
|
27
|
+
# This will create a scenario, run the block after 2 events have been
|
28
|
+
# collected, and then return again after 1 more event has been collected.
|
29
|
+
#
|
30
|
+
# You can then check the events with the custom matcher
|
31
|
+
#
|
32
|
+
# dws.events.should be_events_like( ... )
|
33
|
+
#
|
34
|
+
class Scenario
|
35
|
+
include DirectoryWatcher::Logable
|
36
|
+
|
37
|
+
attr_reader :watcher
|
38
|
+
def initialize( watcher )
|
39
|
+
@watcher = watcher
|
40
|
+
@config = watcher.config
|
41
|
+
@observer = EventObserver.new( logger )
|
42
|
+
@watcher.add_observer( @observer )
|
43
|
+
reset
|
44
|
+
end
|
45
|
+
|
46
|
+
def run_and_wait_for_event_count(count, &block )
|
47
|
+
before_count = @observer.events.size
|
48
|
+
@watcher.resume
|
49
|
+
logger.debug "Before yielding event_count = #{before_count}"
|
50
|
+
logger.debug @observer.events.inspect
|
51
|
+
yield self
|
52
|
+
wait_for_events( before_count + count )
|
53
|
+
return self
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_and_wait_for_scan_count(count, &block)
|
57
|
+
@watcher.resume
|
58
|
+
yield self
|
59
|
+
wait_for_scan_count( count )
|
60
|
+
return self
|
61
|
+
end
|
62
|
+
|
63
|
+
def events
|
64
|
+
@observer.events
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop
|
68
|
+
@watcher.stop
|
69
|
+
end
|
70
|
+
|
71
|
+
def pause
|
72
|
+
@watcher.pause
|
73
|
+
end
|
74
|
+
|
75
|
+
def resume
|
76
|
+
@watcher.resume
|
77
|
+
end
|
78
|
+
|
79
|
+
def reset
|
80
|
+
@observer.events.clear
|
81
|
+
@watcher.start
|
82
|
+
@watcher.pause
|
83
|
+
logger.debug "Scenario#reset with pause"
|
84
|
+
end
|
85
|
+
|
86
|
+
def run_once_and_wait_for_event_count( count, &block )
|
87
|
+
@watcher.resume
|
88
|
+
@watcher.stop
|
89
|
+
before_count = @observer.events.size
|
90
|
+
yield self
|
91
|
+
@watcher.run_once
|
92
|
+
wait_for_events( before_count + count )
|
93
|
+
return self
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def wait_for_events( limit )
|
99
|
+
#Thread.pass until @observer.events.size >= limit
|
100
|
+
until @observer.events.size >= limit do
|
101
|
+
Thread.pass
|
102
|
+
sleep(0.01)
|
103
|
+
logger.debug "Waiting for #{limit} events, I have #{@observer.events.size}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def wait_for_scan_count( limit )
|
108
|
+
@watcher.maximum_iterations = limit
|
109
|
+
#Thread.pass until @watcher.finished_scans?
|
110
|
+
until @watcher.finished_scans?
|
111
|
+
sleep(0.01)
|
112
|
+
logger.debug "Waiting for scan count #{limit} got #{@watcher.scans} #{@watcher.maximum_iterations}"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.1
|
metadata
CHANGED
@@ -1,60 +1,145 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directory_watcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tim Pease
|
9
|
+
- Jeremy Hinegardner
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2013-03-20 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
16
|
+
name: rev
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
+
version: 0.3.2
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.3.2
|
25
31
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
32
|
+
name: eventmachine
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
28
34
|
none: false
|
29
35
|
requirements:
|
30
36
|
- - ! '>='
|
31
37
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
38
|
+
version: 1.0.3
|
33
39
|
type: :development
|
34
40
|
prerelease: false
|
35
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.3
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
38
|
-
requirement:
|
48
|
+
name: cool.io
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
42
53
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
54
|
+
version: 1.1.0
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.1.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bones-git
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.2.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.2.4
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: bones-rspec
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.0.1
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 2.0.1
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rspec
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.7.0
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.7.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: logging
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.6.1
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ~>
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.6.1
|
47
127
|
- !ruby/object:Gem::Dependency
|
48
128
|
name: bones
|
49
|
-
requirement:
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
50
130
|
none: false
|
51
131
|
requirements:
|
52
132
|
- - ! '>='
|
53
133
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
134
|
+
version: 3.8.0
|
55
135
|
type: :development
|
56
136
|
prerelease: false
|
57
|
-
version_requirements:
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: 3.8.0
|
58
143
|
description: ! 'The directory watcher operates by scanning a directory at some interval
|
59
144
|
and
|
60
145
|
|
@@ -66,25 +151,40 @@ description: ! 'The directory watcher operates by scanning a directory at some i
|
|
66
151
|
|
67
152
|
added, modified, and removed.'
|
68
153
|
email: tim.pease@gmail.com
|
69
|
-
executables:
|
70
|
-
- dw
|
154
|
+
executables: []
|
71
155
|
extensions: []
|
72
156
|
extra_rdoc_files:
|
73
157
|
- History.txt
|
74
158
|
- README.txt
|
75
|
-
- bin/dw
|
76
159
|
files:
|
160
|
+
- .gitignore
|
77
161
|
- History.txt
|
78
162
|
- README.txt
|
79
163
|
- Rakefile
|
80
|
-
- bin/dw
|
81
164
|
- lib/directory_watcher.rb
|
165
|
+
- lib/directory_watcher/collector.rb
|
166
|
+
- lib/directory_watcher/configuration.rb
|
82
167
|
- lib/directory_watcher/coolio_scanner.rb
|
83
168
|
- lib/directory_watcher/em_scanner.rb
|
169
|
+
- lib/directory_watcher/event.rb
|
170
|
+
- lib/directory_watcher/eventable_scanner.rb
|
171
|
+
- lib/directory_watcher/file_stat.rb
|
172
|
+
- lib/directory_watcher/logable.rb
|
173
|
+
- lib/directory_watcher/notifier.rb
|
174
|
+
- lib/directory_watcher/paths.rb
|
84
175
|
- lib/directory_watcher/rev_scanner.rb
|
176
|
+
- lib/directory_watcher/scan.rb
|
177
|
+
- lib/directory_watcher/scan_and_queue.rb
|
85
178
|
- lib/directory_watcher/scanner.rb
|
179
|
+
- lib/directory_watcher/threaded.rb
|
180
|
+
- lib/directory_watcher/version.rb
|
181
|
+
- spec/directory_watcher_spec.rb
|
182
|
+
- spec/paths_spec.rb
|
183
|
+
- spec/scanner_scenarios.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
- spec/utility_classes.rb
|
86
186
|
- version.txt
|
87
|
-
homepage: http://
|
187
|
+
homepage: http://rubygems.org/gems/directory_watcher
|
88
188
|
licenses: []
|
89
189
|
post_install_message:
|
90
190
|
rdoc_options:
|
@@ -106,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
206
|
version: '0'
|
107
207
|
requirements: []
|
108
208
|
rubyforge_project: directory_watcher
|
109
|
-
rubygems_version: 1.8.
|
209
|
+
rubygems_version: 1.8.23
|
110
210
|
signing_key:
|
111
211
|
specification_version: 3
|
112
212
|
summary: A class for watching files within a directory and generating events when
|
data/bin/dw
DELETED