filewatcher 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +3 -0
- data/VERSION +1 -1
- data/lib/filewatcher.rb +39 -41
- data/test/test_filewatcher.rb +1 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 931616017d17d3dbca73187c1b6fe31887975115
|
4
|
+
data.tar.gz: 24cec3cbfe8256a906a0067d628438d2bc4176d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eddb01f13c12345438352bb1450f22078462d1b392baacdd0796ddf40a82f80aab5164fc2be36d0c15493cf257164de2f41a2b4a46cfe84400b67c4a1438d6d4
|
7
|
+
data.tar.gz: efeff47ff4fb01fc3e9af4e9f7a0af47fc33d59fa6b67a19d077055438c43c4839428bc4f8ca8de42d74e44093df2f092532a36e27f5e6efa05b91283a25f91c
|
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/filewatcher.rb
CHANGED
@@ -4,40 +4,26 @@
|
|
4
4
|
class FileWatcher
|
5
5
|
|
6
6
|
def self.VERSION
|
7
|
-
return "0.
|
7
|
+
return "0.3.0"
|
8
8
|
end
|
9
9
|
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
filenames = [filenames]
|
13
|
-
end
|
14
|
-
|
15
|
-
filenames = expand_directories(filenames)
|
16
|
-
|
17
|
-
if(print_filelist)
|
18
|
-
if(print_filelist.kind_of?String)
|
19
|
-
puts print_filelist
|
20
|
-
else
|
21
|
-
puts "Watching:"
|
22
|
-
end
|
23
|
-
filenames.each do |filename|
|
24
|
-
puts filename
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
10
|
+
def initialize(unexpanded_filenames, print_filelist=false)
|
11
|
+
@unexpanded_filenames = unexpanded_filenames
|
28
12
|
@last_mtimes = { }
|
29
|
-
filenames
|
13
|
+
@filenames = expand_directories(@unexpanded_filenames)
|
14
|
+
|
15
|
+
puts "Watching:" if print_filelist
|
16
|
+
@filenames.each do |filename|
|
30
17
|
raise "File does not exist" unless File.exist?(filename)
|
31
18
|
@last_mtimes[filename] = File.stat(filename).mtime
|
19
|
+
puts filename if print_filelist
|
32
20
|
end
|
33
|
-
@filenames = filenames
|
34
|
-
@deleted_files = []
|
35
21
|
end
|
36
22
|
|
37
23
|
def watch(sleep=1, &on_update)
|
38
24
|
loop do
|
39
25
|
begin
|
40
|
-
Kernel.sleep sleep until
|
26
|
+
Kernel.sleep sleep until filesystem_updated?
|
41
27
|
rescue SystemExit,Interrupt
|
42
28
|
Kernel.exit
|
43
29
|
end
|
@@ -45,33 +31,45 @@ class FileWatcher
|
|
45
31
|
end
|
46
32
|
end
|
47
33
|
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
if(not(@deleted_files.include?(filename)))
|
34
|
+
def filesystem_updated?
|
35
|
+
filenames = expand_directories(@unexpanded_filenames)
|
52
36
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
37
|
+
if(filenames.size > @filenames.size)
|
38
|
+
filename = (filenames - @filenames).first
|
39
|
+
@filenames << filename
|
40
|
+
@last_mtimes[filename] = File.stat(filename).mtime
|
41
|
+
@updated_file = filename
|
42
|
+
@event = :new
|
43
|
+
return true
|
44
|
+
end
|
60
45
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
46
|
+
if(filenames.size < @filenames.size)
|
47
|
+
filename = (@filenames - filenames).first
|
48
|
+
@filenames.delete(filename)
|
49
|
+
@last_mtimes.delete(filename)
|
50
|
+
@updated_file = filename
|
51
|
+
@event = :delete
|
52
|
+
return true
|
53
|
+
end
|
68
54
|
|
55
|
+
@filenames.each do |filename|
|
56
|
+
mtime = File.stat(filename).mtime
|
57
|
+
updated = @last_mtimes[filename] < mtime
|
58
|
+
@last_mtimes[filename] = mtime
|
59
|
+
if(updated)
|
60
|
+
@updated_file = filename
|
61
|
+
@event = :changed
|
62
|
+
return true
|
69
63
|
end
|
70
64
|
end
|
65
|
+
|
71
66
|
return false
|
72
67
|
end
|
73
68
|
|
74
69
|
def expand_directories(filenames)
|
70
|
+
if(filenames.kind_of?String)
|
71
|
+
filenames = [filenames]
|
72
|
+
end
|
75
73
|
files = []
|
76
74
|
filenames.each do |filename|
|
77
75
|
if(File.directory?(filename))
|
data/test/test_filewatcher.rb
CHANGED
@@ -5,22 +5,12 @@ class TestFilewatcher < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
should "should detect directories and extract filenames" do
|
7
7
|
|
8
|
-
puts " "
|
9
|
-
|
10
8
|
FileWatcher.new(["test/"],"Watching files. Ctrl-C to abort.").watch(0.1) do |filename, event|
|
11
|
-
puts "updated:
|
12
|
-
end
|
13
|
-
|
14
|
-
FileWatcher.new(["./test/", "Rakefile", "lib"]).watch(0.1) do |filename|
|
15
|
-
puts "updated: " + filename
|
9
|
+
puts "updated: '#{filename.to_s} event:'#{event.to_s}'"
|
16
10
|
end
|
17
11
|
|
18
12
|
end
|
19
13
|
|
20
|
-
should "return version number" do
|
21
|
-
assert FileWatcher.VERSION.size > 2
|
22
|
-
end
|
23
|
-
|
24
14
|
# should "should detect changes in files" do
|
25
15
|
|
26
16
|
# @pid = fork do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thoughtbot-shoulda
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.0.
|
77
|
+
rubygems_version: 2.0.3
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Simple filewatcher.
|