watchr 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/History.txt +32 -0
- data/Manifest +27 -0
- data/README.rdoc +6 -4
- data/TODO.txt +2 -0
- data/gem.watchr +32 -0
- data/lib/watchr.rb +2 -2
- data/lib/watchr/controller.rb +2 -2
- data/lib/watchr/event_handlers/base.rb +3 -4
- data/lib/watchr/event_handlers/portable.rb +1 -1
- data/lib/watchr/event_handlers/unix.rb +38 -1
- data/lib/watchr/script.rb +35 -19
- data/manifest.watchr +70 -0
- data/test/README +11 -0
- data/test/event_handlers/test_portable.rb +1 -1
- data/test/event_handlers/test_unix.rb +106 -4
- data/test/test_controller.rb +3 -3
- data/test/test_script.rb +26 -3
- data/watchr.gemspec +18 -12
- metadata +19 -13
data/History.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
=== v0.5.7
|
3
|
+
|
4
|
+
* Added manifest.watchr script
|
5
|
+
* Unix handler supports :deleted event type
|
6
|
+
* Unix handler supports :accessed (atime), :modified (mtime) and :changed
|
7
|
+
(ctime) event types (thanks gzuki[http://github.com/gzuki] for initial work)
|
8
|
+
|
9
|
+
|
10
|
+
=== v0.5.6
|
11
|
+
|
12
|
+
* Rev gem optional in development (thanks TwP[http://github.com/TwP])
|
13
|
+
* Allow gems to bundle .watchr scripts (thanks foca[http://github.com/foca])
|
14
|
+
|
15
|
+
gemname/lib/gemname.watchr
|
16
|
+
|
17
|
+
is now automatically picked up with
|
18
|
+
|
19
|
+
$ watchr gemname.watchr
|
20
|
+
|
21
|
+
* Look for script in path
|
22
|
+
* debug msg when rev not found on *nix
|
23
|
+
* rake task for cross interpreter testing
|
24
|
+
|
25
|
+
|
26
|
+
=== v0.5.5
|
27
|
+
|
28
|
+
* Rev gem is optional. Fixes issue #1
|
29
|
+
Install Rev to automatically get evented handler on *nix
|
30
|
+
|
31
|
+
gem install rev
|
32
|
+
|
data/Manifest
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
.gitignore
|
2
|
+
History.txt
|
3
|
+
LICENSE
|
4
|
+
Manifest
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
TODO.txt
|
8
|
+
bin/watchr
|
9
|
+
docs.watchr
|
10
|
+
gem.watchr
|
11
|
+
lib/watchr.rb
|
12
|
+
lib/watchr/controller.rb
|
13
|
+
lib/watchr/event_handlers/base.rb
|
14
|
+
lib/watchr/event_handlers/portable.rb
|
15
|
+
lib/watchr/event_handlers/unix.rb
|
16
|
+
lib/watchr/script.rb
|
17
|
+
manifest.watchr
|
18
|
+
specs.watchr
|
19
|
+
test/README
|
20
|
+
test/event_handlers/test_base.rb
|
21
|
+
test/event_handlers/test_portable.rb
|
22
|
+
test/event_handlers/test_unix.rb
|
23
|
+
test/test_controller.rb
|
24
|
+
test/test_helper.rb
|
25
|
+
test/test_script.rb
|
26
|
+
test/test_watchr.rb
|
27
|
+
watchr.gemspec
|
data/README.rdoc
CHANGED
@@ -99,8 +99,10 @@ docs:: http://docs.github.com/mynyml/watchr
|
|
99
99
|
wiki:: http://wiki.github.com/mynyml/watchr
|
100
100
|
bugs:: http://github.com/mynyml/watchr/issues
|
101
101
|
|
102
|
-
===
|
102
|
+
=== Contributions
|
103
|
+
|
104
|
+
macournoyer[http://github.com/macournoyer]:: suggested evented backend
|
105
|
+
foca[http://github.com/foca]:: suggested automatically picking up watchr scripts bundled in gems
|
106
|
+
TwP[http://github.com/TwP]:: patch, Rev gem optional in development
|
107
|
+
gzuki[http://github.com/gzuki]:: patch, recognize some event types
|
103
108
|
|
104
|
-
* macournoyer[http://github.com/macournoyer] for the evented backend idea
|
105
|
-
* foca[http://github.com/foca] for suggesting automatically picking up watchr
|
106
|
-
scripts bundled in gems
|
data/TODO.txt
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
* sometimes an action is fired without a file being saved
|
5
5
|
* buffer flushing issue?
|
6
6
|
* libev issue?
|
7
|
+
* probably fixed with event type handling update, which ignores atime
|
8
|
+
updates by defaults
|
7
9
|
|
8
10
|
* when a file is saved twice quickly, subsequent events are ignored.
|
9
11
|
* seems like rev/libev drops the file watch
|
data/gem.watchr
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Run me with:
|
2
|
+
#
|
3
|
+
# $ watchr gem.watchr
|
4
|
+
|
5
|
+
# --------------------------------------------------
|
6
|
+
# Convenience Methods
|
7
|
+
# --------------------------------------------------
|
8
|
+
def build(gemspec)
|
9
|
+
system "gem build %s" % gemspec
|
10
|
+
FileUtils.mv Dir['watchr-*.gem'], 'pkg/'
|
11
|
+
puts
|
12
|
+
end
|
13
|
+
|
14
|
+
# --------------------------------------------------
|
15
|
+
# Watchr Rules
|
16
|
+
# --------------------------------------------------
|
17
|
+
watch( '^watchr.gemspec$' ) { |m| build m[0] }
|
18
|
+
|
19
|
+
# --------------------------------------------------
|
20
|
+
# Signal Handling
|
21
|
+
# --------------------------------------------------
|
22
|
+
# Ctrl-\
|
23
|
+
Signal.trap('QUIT') do
|
24
|
+
puts " --- Building Gem ---\n\n"
|
25
|
+
build 'watchr.gemspec'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Ctrl-C
|
29
|
+
Signal.trap('INT') { abort("\n") }
|
30
|
+
|
31
|
+
|
32
|
+
# vim:ft=ruby
|
data/lib/watchr.rb
CHANGED
@@ -13,6 +13,8 @@ require 'rbconfig'
|
|
13
13
|
# See README for more details
|
14
14
|
#
|
15
15
|
module Watchr
|
16
|
+
VERSION = '0.5.7'
|
17
|
+
|
16
18
|
begin
|
17
19
|
require 'rev'
|
18
20
|
HAVE_REV = true
|
@@ -29,8 +31,6 @@ module Watchr
|
|
29
31
|
autoload :Portable, 'watchr/event_handlers/portable'
|
30
32
|
end
|
31
33
|
|
32
|
-
VERSION = '0.5.6'
|
33
|
-
|
34
34
|
class << self
|
35
35
|
attr_accessor :options
|
36
36
|
attr_accessor :handler
|
data/lib/watchr/controller.rb
CHANGED
@@ -48,14 +48,14 @@ module Watchr
|
|
48
48
|
# path<Pathname, String>:: path that triggered event
|
49
49
|
# event<Symbol>:: event type (ignored for now)
|
50
50
|
#
|
51
|
-
def update(path,
|
51
|
+
def update(path, event_type = nil)
|
52
52
|
path = Pathname(path).expand_path
|
53
53
|
|
54
54
|
if path == @script.path
|
55
55
|
@script.parse!
|
56
56
|
@handler.refresh(monitored_paths)
|
57
57
|
else
|
58
|
-
@script.action_for(path).call
|
58
|
+
@script.action_for(path, event_type).call
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -13,13 +13,12 @@ module Watchr
|
|
13
13
|
#
|
14
14
|
# ===== Parameters
|
15
15
|
# path<Pathname, String>:: full path or path relative to current working directory
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# event_type<Symbol>:: event type.
|
18
17
|
#--
|
19
18
|
# #changed and #notify_observers are Observable methods
|
20
|
-
def notify(path,
|
19
|
+
def notify(path, event_type = nil)
|
21
20
|
changed(true)
|
22
|
-
notify_observers(path,
|
21
|
+
notify_observers(path, event_type)
|
23
22
|
end
|
24
23
|
|
25
24
|
# Begin watching given paths and enter listening loop. Called by the controller.
|
@@ -12,10 +12,47 @@ module Watchr
|
|
12
12
|
attr_accessor :handler
|
13
13
|
end
|
14
14
|
|
15
|
+
def initialize(path)
|
16
|
+
super
|
17
|
+
update_reference_times
|
18
|
+
end
|
19
|
+
|
20
|
+
# File's path as a Pathname
|
21
|
+
def pathname
|
22
|
+
@pathname ||= Pathname(@path)
|
23
|
+
end
|
24
|
+
|
15
25
|
# Callback. Called on file change event
|
16
26
|
# Delegates to Controller#update, passing in path and event type
|
17
27
|
def on_change
|
18
|
-
self.class.handler.notify(path,
|
28
|
+
self.class.handler.notify(path, type)
|
29
|
+
update_reference_times unless type == :deleted
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def update_reference_times
|
35
|
+
@reference_atime = pathname.atime
|
36
|
+
@reference_mtime = pathname.mtime
|
37
|
+
@reference_ctime = pathname.ctime
|
38
|
+
end
|
39
|
+
|
40
|
+
# Type of latest event.
|
41
|
+
#
|
42
|
+
# A single type is determined, even though more than one stat times may
|
43
|
+
# have changed on the file. The type is the first to match in the
|
44
|
+
# following hierarchy:
|
45
|
+
#
|
46
|
+
# :deleted, :modified (mtime), :accessed (atime), :changed (ctime)
|
47
|
+
#
|
48
|
+
# ===== Returns
|
49
|
+
# type<Symbol>:: latest event's type
|
50
|
+
#
|
51
|
+
def type
|
52
|
+
return :deleted if !pathname.exist?
|
53
|
+
return :modified if pathname.mtime > @reference_mtime
|
54
|
+
return :accessed if pathname.atime > @reference_atime
|
55
|
+
return :changed if pathname.ctime > @reference_ctime
|
19
56
|
end
|
20
57
|
end
|
21
58
|
|
data/lib/watchr/script.rb
CHANGED
@@ -8,6 +8,7 @@ module Watchr
|
|
8
8
|
# script = Watchr::Script.new(path)
|
9
9
|
#
|
10
10
|
class Script
|
11
|
+
DEFAULT_EVENT_TYPE = :modified
|
11
12
|
|
12
13
|
# Convenience type. Provides clearer and simpler access to rule properties.
|
13
14
|
#
|
@@ -17,7 +18,7 @@ module Watchr
|
|
17
18
|
# rule.pattern #=> 'lib/.*\.rb'
|
18
19
|
# rule.action.call #=> 'ohaie'
|
19
20
|
#
|
20
|
-
Rule = Struct.new(:pattern, :action)
|
21
|
+
Rule = Struct.new(:pattern, :event_type, :action)
|
21
22
|
|
22
23
|
# TODO eval context
|
23
24
|
class API #:nodoc:
|
@@ -69,13 +70,18 @@ module Watchr
|
|
69
70
|
#
|
70
71
|
# ===== Parameters
|
71
72
|
# pattern<~#match>:: pattern to match targetted paths
|
73
|
+
# event_type<Symbol>::
|
74
|
+
# Rule will only match events of this type. Accepted types are :accessed,
|
75
|
+
# :modified, :changed, :delete and nil (any), where the first three
|
76
|
+
# correspond to atime, mtime and ctime respectively. Defaults to
|
77
|
+
# :modified.
|
72
78
|
# action<Block>:: action to trigger
|
73
79
|
#
|
74
80
|
# ===== Returns
|
75
81
|
# rule<Rule>:: rule created by the method
|
76
82
|
#
|
77
|
-
def watch(pattern, &action)
|
78
|
-
@rules << Rule.new(pattern, action || @default_action)
|
83
|
+
def watch(pattern, event_type = DEFAULT_EVENT_TYPE, &action)
|
84
|
+
@rules << Rule.new(pattern, event_type, action || @default_action)
|
79
85
|
@rules.last
|
80
86
|
end
|
81
87
|
|
@@ -120,24 +126,28 @@ module Watchr
|
|
120
126
|
instance_eval(@path.read)
|
121
127
|
end
|
122
128
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
# Find
|
129
|
-
#
|
129
|
+
# Find an action corresponding to a path and event type. The returned
|
130
|
+
# action is actually a wrapper around the rule's action, with the
|
131
|
+
# match_data prepopulated.
|
132
|
+
#
|
133
|
+
# ===== Params
|
134
|
+
# path<Pathnane,String>:: Find action that correspond to this path.
|
135
|
+
# event_type<Symbol>:: Find action only if rule's event if of this type.
|
130
136
|
#
|
131
137
|
# ===== Examples
|
132
138
|
#
|
133
139
|
# script.watch( 'test/test_.*\.rb' ) {|md| "ruby #{md[0]}" }
|
134
140
|
# script.action_for('test/test_watchr.rb').call #=> "ruby test/test_watchr.rb"
|
135
141
|
#
|
136
|
-
def action_for(path)
|
142
|
+
def action_for(path, event_type = DEFAULT_EVENT_TYPE)
|
137
143
|
path = rel_path(path).to_s
|
138
|
-
rule =
|
139
|
-
|
140
|
-
|
144
|
+
rule = rules_for(path).detect {|rule| rule.event_type.nil? || rule.event_type == event_type }
|
145
|
+
if rule
|
146
|
+
data = path.match(rule.pattern)
|
147
|
+
lambda { rule.action.call(data) }
|
148
|
+
else
|
149
|
+
lambda {}
|
150
|
+
end
|
141
151
|
end
|
142
152
|
|
143
153
|
# Collection of all patterns defined in script.
|
@@ -161,17 +171,17 @@ module Watchr
|
|
161
171
|
|
162
172
|
private
|
163
173
|
|
164
|
-
#
|
165
|
-
#
|
174
|
+
# Rules corresponding to a given path, in reversed order of precedence
|
175
|
+
# (latest one is most inportant).
|
166
176
|
#
|
167
177
|
# ===== Parameters
|
168
178
|
# path<Pathname, String>:: path to look up rule for
|
169
179
|
#
|
170
180
|
# ===== Returns
|
171
|
-
#
|
181
|
+
# rules<Array(Rule)>:: rules corresponding to <tt>path</tt>
|
172
182
|
#
|
173
|
-
def
|
174
|
-
@rules.reverse.
|
183
|
+
def rules_for(path)
|
184
|
+
@rules.reverse.select {|rule| path.match(rule.pattern) }
|
175
185
|
end
|
176
186
|
|
177
187
|
# Make a path relative to current working directory.
|
@@ -185,5 +195,11 @@ module Watchr
|
|
185
195
|
def rel_path(path)
|
186
196
|
Pathname(path).expand_path.relative_path_from(Pathname(Dir.pwd))
|
187
197
|
end
|
198
|
+
|
199
|
+
# Reset script state
|
200
|
+
def reset
|
201
|
+
@default_action = lambda {}
|
202
|
+
@rules.clear
|
203
|
+
end
|
188
204
|
end
|
189
205
|
end
|
data/manifest.watchr
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Run me with:
|
2
|
+
#
|
3
|
+
# $ watchr manifest.watchr
|
4
|
+
#
|
5
|
+
# This script will remove a file from from the Manifest when it gets deleted,
|
6
|
+
# and will rebuild the Manifest on Ctrl-\
|
7
|
+
#
|
8
|
+
# Mostly serves as a demo for the :delete event type (and eventually for the
|
9
|
+
# :added event type). In reality this is much better implemented as a git
|
10
|
+
# post-commit script.
|
11
|
+
#
|
12
|
+
|
13
|
+
require 'pathname'
|
14
|
+
# --------------------------------------------------
|
15
|
+
# Helpers
|
16
|
+
# --------------------------------------------------
|
17
|
+
module Project
|
18
|
+
extend self
|
19
|
+
def files
|
20
|
+
`git ls-files --full-name`.strip.split($/).sort
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Manifest
|
25
|
+
attr_accessor :path
|
26
|
+
|
27
|
+
def initialize(path)
|
28
|
+
@path = Pathname(path).expand_path
|
29
|
+
create!
|
30
|
+
end
|
31
|
+
|
32
|
+
def remove(path)
|
33
|
+
paths = @path.read.strip.split($/)
|
34
|
+
@path.open('w') {|f| f << (paths - [path]).join("\n") }
|
35
|
+
end
|
36
|
+
|
37
|
+
def add(path)
|
38
|
+
paths = @path.read.strip.split($/)
|
39
|
+
@path.open('w') {|f| f << paths.push(path).sort.join("\n") }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def create!
|
44
|
+
File.open(@path.to_s, 'w') {} unless @path.exist?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
@manifest = Manifest.new('Manifest')
|
50
|
+
|
51
|
+
# --------------------------------------------------
|
52
|
+
# Watchr Rules
|
53
|
+
# --------------------------------------------------
|
54
|
+
watch('.*', :deleted ) do |md|
|
55
|
+
@manifest.remove(md[0])
|
56
|
+
puts "removed #{md[0].inspect} from Manifest"
|
57
|
+
end
|
58
|
+
|
59
|
+
# --------------------------------------------------
|
60
|
+
# Signal Handling
|
61
|
+
# --------------------------------------------------
|
62
|
+
# Ctrl-\
|
63
|
+
Signal.trap('QUIT') do
|
64
|
+
puts " --- Updated Manifest ---\n"
|
65
|
+
@manifest.path.open('w') {|m| m << Project.files.join("\n").strip }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Ctrl-C
|
69
|
+
Signal.trap('INT') { abort("\n") }
|
70
|
+
|
data/test/README
ADDED
@@ -35,7 +35,7 @@ class PortableEventHandlerTest < Test::Unit::TestCase
|
|
35
35
|
@foo.stubs(:mtime).returns(Time.now + 100) # fake event
|
36
36
|
|
37
37
|
@handler.listen [ @foo, @bar ]
|
38
|
-
@handler.expects(:notify).with(@foo, :
|
38
|
+
@handler.expects(:notify).with(@foo, :modified)
|
39
39
|
@handler.trigger
|
40
40
|
end
|
41
41
|
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
1
3
|
if Watchr::HAVE_REV
|
2
4
|
|
3
|
-
|
5
|
+
class Watchr::EventHandler::Unix::SingleFileWatcher
|
6
|
+
public :type
|
7
|
+
end
|
4
8
|
|
5
9
|
class UnixEventHandlerTest < Test::Unit::TestCase
|
6
10
|
include Watchr
|
@@ -8,8 +12,17 @@ class UnixEventHandlerTest < Test::Unit::TestCase
|
|
8
12
|
SingleFileWatcher = EventHandler::Unix::SingleFileWatcher
|
9
13
|
|
10
14
|
def setup
|
15
|
+
@now = Time.now
|
16
|
+
pathname = Pathname.new('foo/bar')
|
17
|
+
pathname.stubs(:atime ).returns(@now)
|
18
|
+
pathname.stubs(:mtime ).returns(@now)
|
19
|
+
pathname.stubs(:ctime ).returns(@now)
|
20
|
+
pathname.stubs(:exist?).returns(true)
|
21
|
+
SingleFileWatcher.any_instance.stubs(:pathname).returns(pathname)
|
22
|
+
|
11
23
|
@loop = Rev::Loop.default
|
12
24
|
@handler = EventHandler::Unix.new
|
25
|
+
@watcher = SingleFileWatcher.new('foo/bar')
|
13
26
|
@loop.stubs(:run)
|
14
27
|
end
|
15
28
|
|
@@ -23,6 +36,60 @@ class UnixEventHandlerTest < Test::Unit::TestCase
|
|
23
36
|
@handler.listen([])
|
24
37
|
end
|
25
38
|
|
39
|
+
## SingleFileWatcher
|
40
|
+
|
41
|
+
test "watcher pathname" do
|
42
|
+
@watcher.pathname.should be_kind_of(Pathname)
|
43
|
+
@watcher.pathname.to_s.should be(@watcher.path)
|
44
|
+
end
|
45
|
+
|
46
|
+
test "stores reference times" do
|
47
|
+
@watcher.pathname.stubs(:atime).returns(:time)
|
48
|
+
@watcher.pathname.stubs(:mtime).returns(:time)
|
49
|
+
@watcher.pathname.stubs(:ctime).returns(:time)
|
50
|
+
|
51
|
+
@watcher.send(:update_reference_times)
|
52
|
+
@watcher.instance_variable_get(:@reference_atime).should be(:time)
|
53
|
+
@watcher.instance_variable_get(:@reference_mtime).should be(:time)
|
54
|
+
@watcher.instance_variable_get(:@reference_ctime).should be(:time)
|
55
|
+
end
|
56
|
+
|
57
|
+
test "stores initial reference times" do
|
58
|
+
SingleFileWatcher.any_instance.expects(:update_reference_times)
|
59
|
+
SingleFileWatcher.new('foo')
|
60
|
+
end
|
61
|
+
|
62
|
+
test "updates reference times on change" do
|
63
|
+
@watcher.expects(:update_reference_times)
|
64
|
+
@watcher.on_change
|
65
|
+
end
|
66
|
+
|
67
|
+
test "detects event type" do
|
68
|
+
trigger_event @watcher, @now, :atime
|
69
|
+
@watcher.type.should be(:accessed)
|
70
|
+
|
71
|
+
trigger_event @watcher, @now, :mtime
|
72
|
+
@watcher.type.should be(:modified)
|
73
|
+
|
74
|
+
trigger_event @watcher, @now, :ctime
|
75
|
+
@watcher.type.should be(:changed)
|
76
|
+
|
77
|
+
trigger_event @watcher, @now, :atime, :mtime
|
78
|
+
@watcher.type.should be(:modified)
|
79
|
+
|
80
|
+
trigger_event @watcher, @now, :mtime, :ctime
|
81
|
+
@watcher.type.should be(:modified)
|
82
|
+
|
83
|
+
trigger_event @watcher, @now, :atime, :ctime
|
84
|
+
@watcher.type.should be(:accessed)
|
85
|
+
|
86
|
+
trigger_event @watcher, @now, :atime, :mtime, :ctime
|
87
|
+
@watcher.type.should be(:modified)
|
88
|
+
|
89
|
+
@watcher.pathname.stubs(:exist?).returns(false)
|
90
|
+
@watcher.type.should be(:deleted)
|
91
|
+
end
|
92
|
+
|
26
93
|
## monitoring file events
|
27
94
|
|
28
95
|
test "listens for events on monitored files" do
|
@@ -33,11 +100,31 @@ class UnixEventHandlerTest < Test::Unit::TestCase
|
|
33
100
|
end
|
34
101
|
|
35
102
|
test "notifies observers on file event" do
|
36
|
-
watcher
|
37
|
-
|
103
|
+
@watcher.stubs(:path).returns('foo')
|
104
|
+
@handler.expects(:notify).with('foo', anything)
|
105
|
+
@watcher.on_change
|
106
|
+
end
|
38
107
|
|
108
|
+
test "notifies observers of event type" do
|
109
|
+
trigger_event @watcher, @now, :atime
|
110
|
+
@handler.expects(:notify).with('foo/bar', :accessed)
|
111
|
+
@watcher.on_change
|
112
|
+
|
113
|
+
trigger_event @watcher, @now, :mtime
|
114
|
+
@handler.expects(:notify).with('foo/bar', :modified)
|
115
|
+
@watcher.on_change
|
116
|
+
|
117
|
+
trigger_event @watcher, @now, :ctime
|
39
118
|
@handler.expects(:notify).with('foo/bar', :changed)
|
40
|
-
watcher.on_change
|
119
|
+
@watcher.on_change
|
120
|
+
|
121
|
+
trigger_event @watcher, @now, :atime, :mtime, :ctime
|
122
|
+
@handler.expects(:notify).with('foo/bar', :modified)
|
123
|
+
@watcher.on_change
|
124
|
+
|
125
|
+
@watcher.pathname.stubs(:exist?).returns(false)
|
126
|
+
@handler.expects(:notify).with('foo/bar', :deleted)
|
127
|
+
@watcher.on_change
|
41
128
|
end
|
42
129
|
|
43
130
|
## on the fly updates of monitored files list
|
@@ -55,6 +142,21 @@ class UnixEventHandlerTest < Test::Unit::TestCase
|
|
55
142
|
@loop.watchers.every.path.should exclude('foo')
|
56
143
|
@loop.watchers.every.path.should exclude('bar')
|
57
144
|
end
|
145
|
+
|
146
|
+
private
|
147
|
+
|
148
|
+
def trigger_event(watcher, now, *types)
|
149
|
+
watcher.pathname.stubs(:atime).returns(now)
|
150
|
+
watcher.pathname.stubs(:mtime).returns(now)
|
151
|
+
watcher.pathname.stubs(:ctime).returns(now)
|
152
|
+
watcher.instance_variable_set(:@reference_atime, now)
|
153
|
+
watcher.instance_variable_set(:@reference_mtime, now)
|
154
|
+
watcher.instance_variable_set(:@reference_ctime, now)
|
155
|
+
|
156
|
+
types.each do |type|
|
157
|
+
watcher.pathname.stubs(type).returns(now+10)
|
158
|
+
end
|
159
|
+
end
|
58
160
|
end
|
59
161
|
|
60
162
|
end # if Watchr::HAVE_REV
|
data/test/test_controller.rb
CHANGED
@@ -78,9 +78,9 @@ class TestController < Test::Unit::TestCase
|
|
78
78
|
|
79
79
|
test "calls action for path" do
|
80
80
|
path = to_p('abc')
|
81
|
-
@script.expects(:action_for).with(path).returns(lambda {})
|
81
|
+
@script.expects(:action_for).with(path, :modified).returns(lambda {})
|
82
82
|
|
83
|
-
@controller.update('abc')
|
83
|
+
@controller.update('abc', :modified)
|
84
84
|
end
|
85
85
|
|
86
86
|
test "parses script on script file update" do
|
@@ -97,7 +97,7 @@ class TestController < Test::Unit::TestCase
|
|
97
97
|
@controller.stubs(:monitored_paths).returns %w( foo bar )
|
98
98
|
|
99
99
|
@handler.expects(:refresh).with %w( foo bar )
|
100
|
-
@controller.update(
|
100
|
+
@controller.update(path)
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
data/test/test_script.rb
CHANGED
@@ -12,6 +12,7 @@ class TestScript < Test::Unit::TestCase
|
|
12
12
|
|
13
13
|
test "watch" do
|
14
14
|
@script.watch('pattern')
|
15
|
+
@script.watch('pattern', :event_type)
|
15
16
|
@script.watch('pattern') { nil }
|
16
17
|
end
|
17
18
|
|
@@ -22,17 +23,40 @@ class TestScript < Test::Unit::TestCase
|
|
22
23
|
## functionality
|
23
24
|
|
24
25
|
test "rule object" do
|
25
|
-
rule = @script.watch('pattern') { nil }
|
26
|
+
rule = @script.watch('pattern', :modified) { nil }
|
26
27
|
rule.pattern.should be('pattern')
|
28
|
+
rule.event_type.should be(:modified)
|
27
29
|
rule.action.call.should be(nil)
|
28
30
|
end
|
29
31
|
|
32
|
+
test "default event type" do
|
33
|
+
rule = @script.watch('pattern') { nil }
|
34
|
+
rule.event_type.should be(:modified)
|
35
|
+
end
|
36
|
+
|
30
37
|
test "finds action for path" do
|
31
38
|
@script.watch('abc') { :x }
|
32
39
|
@script.watch('def') { :y }
|
33
40
|
@script.action_for('abc').call.should be(:x)
|
34
41
|
end
|
35
42
|
|
43
|
+
test "finds action for path with event type" do
|
44
|
+
@script.watch('abc', :accessed) { :x }
|
45
|
+
@script.watch('abc', :modified) { :y }
|
46
|
+
@script.action_for('abc', :accessed).call.should be(:x)
|
47
|
+
end
|
48
|
+
|
49
|
+
test "finds action for path with any event type" do
|
50
|
+
@script.watch('abc', nil) { :x }
|
51
|
+
@script.watch('abc', :modified) { :y }
|
52
|
+
@script.action_for('abc', :accessed).call.should be(:x)
|
53
|
+
end
|
54
|
+
|
55
|
+
test "no action for path" do
|
56
|
+
@script.watch('abc', :accessed) { :x }
|
57
|
+
@script.action_for('abc', :modified).call.should be(nil)
|
58
|
+
end
|
59
|
+
|
36
60
|
test "collects patterns" do
|
37
61
|
@script.watch('abc')
|
38
62
|
@script.watch('def')
|
@@ -52,8 +76,7 @@ class TestScript < Test::Unit::TestCase
|
|
52
76
|
test "resets state" do
|
53
77
|
@script.default_action { 'x' }
|
54
78
|
@script.watch('foo') { 'bar' }
|
55
|
-
@script.reset
|
56
|
-
@script.instance_variable_get(:@default_action).should be_kind_of(Proc)
|
79
|
+
@script.send(:reset)
|
57
80
|
@script.instance_variable_get(:@default_action).call.should be(nil)
|
58
81
|
@script.instance_variable_get(:@rules).should be([])
|
59
82
|
end
|
data/watchr.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'watchr'
|
4
|
-
s.version = '0.5.
|
4
|
+
s.version = '0.5.7'
|
5
5
|
s.summary = "Modern continious testing (flexible alternative to autotest)"
|
6
6
|
s.description = "Modern continious testing (flexible alternative to autotest)."
|
7
7
|
s.author = "mynyml"
|
@@ -14,26 +14,32 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.bindir = "bin"
|
15
15
|
s.executables = "watchr"
|
16
16
|
s.files = %w[
|
17
|
-
|
17
|
+
.gitignore
|
18
|
+
History.txt
|
18
19
|
LICENSE
|
19
|
-
|
20
|
+
Manifest
|
21
|
+
README.rdoc
|
20
22
|
Rakefile
|
23
|
+
TODO.txt
|
21
24
|
bin/watchr
|
25
|
+
docs.watchr
|
26
|
+
gem.watchr
|
22
27
|
lib/watchr.rb
|
23
|
-
lib/watchr/script.rb
|
24
28
|
lib/watchr/controller.rb
|
25
29
|
lib/watchr/event_handlers/base.rb
|
26
|
-
lib/watchr/event_handlers/unix.rb
|
27
30
|
lib/watchr/event_handlers/portable.rb
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
lib/watchr/event_handlers/unix.rb
|
32
|
+
lib/watchr/script.rb
|
33
|
+
manifest.watchr
|
34
|
+
specs.watchr
|
35
|
+
test/README
|
32
36
|
test/event_handlers/test_base.rb
|
33
|
-
test/event_handlers/test_unix.rb
|
34
37
|
test/event_handlers/test_portable.rb
|
35
|
-
|
36
|
-
|
38
|
+
test/event_handlers/test_unix.rb
|
39
|
+
test/test_controller.rb
|
40
|
+
test/test_helper.rb
|
41
|
+
test/test_script.rb
|
42
|
+
test/test_watchr.rb
|
37
43
|
watchr.gemspec
|
38
44
|
]
|
39
45
|
s.test_files = %w[
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watchr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mynyml
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-02 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -71,26 +71,32 @@ extensions: []
|
|
71
71
|
extra_rdoc_files:
|
72
72
|
- README.rdoc
|
73
73
|
files:
|
74
|
-
-
|
74
|
+
- .gitignore
|
75
|
+
- History.txt
|
75
76
|
- LICENSE
|
76
|
-
-
|
77
|
+
- Manifest
|
78
|
+
- README.rdoc
|
77
79
|
- Rakefile
|
80
|
+
- TODO.txt
|
78
81
|
- bin/watchr
|
82
|
+
- docs.watchr
|
83
|
+
- gem.watchr
|
79
84
|
- lib/watchr.rb
|
80
|
-
- lib/watchr/script.rb
|
81
85
|
- lib/watchr/controller.rb
|
82
86
|
- lib/watchr/event_handlers/base.rb
|
83
|
-
- lib/watchr/event_handlers/unix.rb
|
84
87
|
- lib/watchr/event_handlers/portable.rb
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
88
|
+
- lib/watchr/event_handlers/unix.rb
|
89
|
+
- lib/watchr/script.rb
|
90
|
+
- manifest.watchr
|
91
|
+
- specs.watchr
|
92
|
+
- test/README
|
89
93
|
- test/event_handlers/test_base.rb
|
90
|
-
- test/event_handlers/test_unix.rb
|
91
94
|
- test/event_handlers/test_portable.rb
|
92
|
-
-
|
93
|
-
-
|
95
|
+
- test/event_handlers/test_unix.rb
|
96
|
+
- test/test_controller.rb
|
97
|
+
- test/test_helper.rb
|
98
|
+
- test/test_script.rb
|
99
|
+
- test/test_watchr.rb
|
94
100
|
- watchr.gemspec
|
95
101
|
has_rdoc: true
|
96
102
|
homepage: http://mynyml.com/ruby/flexible-continuous-testing
|