filewatcher 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +13 -2
- data/VERSION +1 -1
- data/lib/filewatcher.rb +21 -12
- data/test/test_filewatcher.rb +4 -2
- metadata +21 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 18429964b2631c8f50fc42b2a919d3dd859608cd
|
4
|
+
data.tar.gz: e1206dff831c1bb8d2495cc4110b21971c2e6c33
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38c927c846a8844443afb7cb0b403ede8eac5205f3d6833a4220d1e5e6bece967e33602adcdba5b44b922e12bf3300e5043acfb35922067d7cce486de50ddd77
|
7
|
+
data.tar.gz: 6d732bb3d0cfae8f6c57f5477077ccbc9a3b43b631ec58336f8b5953186233b9cdf8bec08fe136e857d747d6f08b1e9a45b7b9ac799e76c3119c1f4f67e0bda1
|
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Run any javascript in current folder when it is updated on Linux/OSX:
|
|
29
29
|
|
30
30
|
In Windows Powershell:
|
31
31
|
|
32
|
-
> filewatcher *.js "node %FILENAME%"
|
32
|
+
> filewatcher *.js "node %FILENAME%"
|
33
33
|
|
34
34
|
Run the ruby script when it is changed:
|
35
35
|
|
@@ -81,12 +81,23 @@ Print the names of files beeing watched before we begin:
|
|
81
81
|
=> Watching files:
|
82
82
|
lib/filewatcher.rb
|
83
83
|
|
84
|
-
To check for changes more often than once every second:
|
84
|
+
To check for changes more often than the default once every second:
|
85
85
|
|
86
86
|
FileWatcher.new(["README.rdoc"]).watch(0.5) do |filename|
|
87
87
|
puts "Updated " + filename
|
88
88
|
end
|
89
89
|
|
90
|
+
To detect if a file is updated or deleted:
|
91
|
+
|
92
|
+
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
93
|
+
if(event == :changed)
|
94
|
+
puts "Updated " + filename
|
95
|
+
end
|
96
|
+
if(event == :deleted)
|
97
|
+
puts "Deleted " + filename
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
90
101
|
= TODO
|
91
102
|
|
92
103
|
The Ruby API is fairly well tested but the command line program is buggy at the time beeing.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/filewatcher.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
class FileWatcher
|
5
5
|
|
6
6
|
def self.VERSION
|
7
|
-
return "0.2.
|
7
|
+
return "0.2.1"
|
8
8
|
end
|
9
9
|
|
10
10
|
def initialize(filenames,print_filelist=false)
|
@@ -31,6 +31,7 @@ class FileWatcher
|
|
31
31
|
@last_mtimes[filename] = File.stat(filename).mtime
|
32
32
|
end
|
33
33
|
@filenames = filenames
|
34
|
+
@deleted_files = []
|
34
35
|
end
|
35
36
|
|
36
37
|
def watch(sleep=1, &on_update)
|
@@ -40,23 +41,31 @@ class FileWatcher
|
|
40
41
|
rescue SystemExit,Interrupt
|
41
42
|
Kernel.exit
|
42
43
|
end
|
43
|
-
yield @updated_file
|
44
|
+
yield @updated_file, @event
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
def file_updated?
|
48
49
|
@filenames.each do |filename|
|
49
|
-
|
50
|
+
|
51
|
+
if(not(@deleted_files.include?(filename)))
|
52
|
+
|
53
|
+
if(not(File.exist?(filename)))
|
54
|
+
@deleted_files << filename
|
55
|
+
@updated_file = filename
|
56
|
+
@event = :delete
|
57
|
+
return true
|
58
|
+
end
|
50
59
|
mtime = File.stat(filename).mtime
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
|
61
|
+
updated = @last_mtimes[filename] < mtime
|
62
|
+
@last_mtimes[filename] = mtime
|
63
|
+
if(updated)
|
64
|
+
@updated_file = filename
|
65
|
+
@event = :changed
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
|
60
69
|
end
|
61
70
|
end
|
62
71
|
return false
|
data/test/test_filewatcher.rb
CHANGED
@@ -5,8 +5,10 @@ class TestFilewatcher < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
should "should detect directories and extract filenames" do
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
puts " "
|
9
|
+
|
10
|
+
FileWatcher.new(["test/"],"Watching files. Ctrl-C to abort.").watch(0.1) do |filename, event|
|
11
|
+
puts "updated: " + filename.to_s + " event:" + event.to_s
|
10
12
|
end
|
11
13
|
|
12
14
|
FileWatcher.new(["./test/", "Rakefile", "lib"]).watch(0.1) do |filename|
|
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Thomas Flemming
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: thoughtbot-shoulda
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: trollop
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - '>='
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: 1.16.2
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.16.2
|
36
41
|
description: Detect changes in files.
|
37
42
|
email: thomas.flemming@gmail.com
|
38
43
|
executables:
|
@@ -52,26 +57,25 @@ files:
|
|
52
57
|
- test/test_filewatcher.rb
|
53
58
|
homepage: http://github.com/thomasfl/filewatcher
|
54
59
|
licenses: []
|
60
|
+
metadata: {}
|
55
61
|
post_install_message:
|
56
62
|
rdoc_options: []
|
57
63
|
require_paths:
|
58
64
|
- lib
|
59
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
-
none: false
|
61
66
|
requirements:
|
62
|
-
- -
|
67
|
+
- - '>='
|
63
68
|
- !ruby/object:Gem::Version
|
64
69
|
version: '0'
|
65
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
71
|
requirements:
|
68
|
-
- -
|
72
|
+
- - '>='
|
69
73
|
- !ruby/object:Gem::Version
|
70
74
|
version: '0'
|
71
75
|
requirements: []
|
72
76
|
rubyforge_project:
|
73
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.0.0
|
74
78
|
signing_key:
|
75
|
-
specification_version:
|
79
|
+
specification_version: 4
|
76
80
|
summary: Simple filewatcher.
|
77
81
|
test_files: []
|