filewatcher 0.1.0 → 0.1.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/README.rdoc +42 -10
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/bin/filewatcher +46 -0
- data/lib/filewatcher.rb +3 -0
- data/test/test_filewatcher.rb +1 -1
- metadata +32 -17
- data/.document +0 -5
- data/.gitignore +0 -21
data/README.rdoc
CHANGED
@@ -1,32 +1,64 @@
|
|
1
1
|
= Filewatcher
|
2
2
|
|
3
|
-
Simple file watcher.
|
3
|
+
Simple file watcher. Monitors changes in files by polling files.
|
4
|
+
|
5
|
+
= Command line utility
|
6
|
+
|
7
|
+
|
8
|
+
Filewatcher scans filesystem and execute shell commands when files changes.
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
filewatcher [-i interval] "<filename>" "<shell command>"
|
12
|
+
Where
|
13
|
+
filename: filename(s) to scan.
|
14
|
+
shell command: shell command to execute when file changes on disk.
|
15
|
+
|
16
|
+
Examples:
|
17
|
+
filewatcher "myfile" "echo 'myfile has changed'"
|
18
|
+
filewathcer -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
|
19
|
+
|
20
|
+
Options:
|
21
|
+
--interval, -i <f>: Interval to scan filesystem. Defaults to 0.5 seconds.
|
22
|
+
--version, -v: Print version and exit
|
23
|
+
--help, -h: Show this message
|
24
|
+
|
25
|
+
|
26
|
+
= Install
|
27
|
+
|
28
|
+
sudo gem install filewatcher
|
29
|
+
|
30
|
+
= API
|
4
31
|
|
5
32
|
Examples:
|
6
33
|
|
34
|
+
Watch a list of files and directories:
|
35
|
+
|
7
36
|
require 'filewatcher'
|
8
37
|
|
9
|
-
FileWatcher.new(["
|
38
|
+
FileWatcher.new(["lib/", "Rakefile"]).watch do |filename|
|
10
39
|
puts "Updated " + filename
|
11
40
|
end
|
12
41
|
|
13
|
-
|
42
|
+
Print the names of files beeing watched before we begin:
|
14
43
|
|
15
|
-
FileWatcher.new(["
|
44
|
+
FileWatcher.new(["lib/"],"Watching files:").watch do |filename|
|
16
45
|
puts "Updated " + filename
|
17
46
|
end
|
47
|
+
=> Watching files:
|
48
|
+
lib/filewatcher.rb
|
18
49
|
|
19
|
-
|
50
|
+
To check for changes more often than once every second:
|
20
51
|
|
21
|
-
FileWatcher.new(["
|
52
|
+
FileWatcher.new(["README.rdoc"]).watch(0.5) do |filename|
|
22
53
|
puts "Updated " + filename
|
23
54
|
end
|
24
55
|
|
25
|
-
To check for changes more often than once every second second:
|
26
56
|
|
27
|
-
|
28
|
-
|
29
|
-
|
57
|
+
= Credits
|
58
|
+
|
59
|
+
Code inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-file-changes-with-ruby
|
60
|
+
|
61
|
+
Find method by c00lrguy: http://snippets.dzone.com/posts/show/5457
|
30
62
|
|
31
63
|
== Note on Patches/Pull Requests
|
32
64
|
|
data/Rakefile
CHANGED
@@ -6,9 +6,10 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "filewatcher"
|
8
8
|
gem.summary = %Q{Simple filewatcher.}
|
9
|
-
gem.description = %Q{Detect
|
9
|
+
gem.description = %Q{Detect changes in files.}
|
10
10
|
gem.email = "thomas.flemming@gmail.com"
|
11
11
|
gem.homepage = "http://github.com/thomasfl/filewatcher"
|
12
|
+
gem.executables = ["filewatcher"]
|
12
13
|
gem.authors = ["Thomas Flemming"]
|
13
14
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/bin/filewatcher
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'filewatcher'
|
4
|
+
require 'trollop'
|
5
|
+
|
6
|
+
options = Trollop::options do
|
7
|
+
version "filewatcher, version 0.1.1 by Thomas Flemming 2011"
|
8
|
+
banner <<-EOS
|
9
|
+
Filewatcher scans filesystem and execute shell commands when files changes.
|
10
|
+
|
11
|
+
Usage:
|
12
|
+
filewatcher [-i interval] "<filename>" "<shell command>"
|
13
|
+
Where
|
14
|
+
filename: filename(s) to scan.
|
15
|
+
shell command: shell command to execute when file changes on disk.
|
16
|
+
|
17
|
+
Examples:
|
18
|
+
filewatcher "myfile" "echo 'myfile has changed'"
|
19
|
+
filewathcer -i 2 "*.rb ../src/*.rb" "ruby run_tests.rb"
|
20
|
+
|
21
|
+
Options:
|
22
|
+
EOS
|
23
|
+
opt :interval, "Interval to scan filesystem. Defaults to 0.5 seconds.", :short => 'i', :type => :float
|
24
|
+
end
|
25
|
+
|
26
|
+
Trollop::die "must have one or two arguments" if(ARGV.size == 0 or ARGV.size > 2)
|
27
|
+
|
28
|
+
interval = 0.5
|
29
|
+
if(options[:interval] > 0.0)then
|
30
|
+
interval = options[:interval]
|
31
|
+
end
|
32
|
+
|
33
|
+
files = []
|
34
|
+
ARGV[0].split(/\s+/).each do |arg|
|
35
|
+
Dir.glob(arg).each do |file|
|
36
|
+
files << file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
FileWatcher.new(files).watch(interval) do |filename|
|
41
|
+
if(ARGV[1])then
|
42
|
+
system(ARGV[1])
|
43
|
+
else
|
44
|
+
puts "file updated: " + filename
|
45
|
+
end
|
46
|
+
end
|
data/lib/filewatcher.rb
CHANGED
data/test/test_filewatcher.rb
CHANGED
@@ -4,7 +4,7 @@ class TestFilewatcher < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
should "should detect directories and extract filenames" do
|
6
6
|
|
7
|
-
FileWatcher.new(["
|
7
|
+
FileWatcher.new(["test/"],"Watching files. Ctrl-C to abort.").watch(0.1) do |filename|
|
8
8
|
puts "updated: " + filename
|
9
9
|
end
|
10
10
|
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Thomas Flemming
|
@@ -9,35 +15,38 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
18
|
+
date: 2011-01-19 00:00:00 +01:00
|
19
|
+
default_executable: filewatcher
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: thoughtbot-shoulda
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
25
|
-
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Detect changes in files.
|
26
36
|
email: thomas.flemming@gmail.com
|
27
|
-
executables:
|
28
|
-
|
37
|
+
executables:
|
38
|
+
- filewatcher
|
29
39
|
extensions: []
|
30
40
|
|
31
41
|
extra_rdoc_files:
|
32
42
|
- LICENSE
|
33
43
|
- README.rdoc
|
34
44
|
files:
|
35
|
-
- .document
|
36
|
-
- .gitignore
|
37
45
|
- LICENSE
|
38
46
|
- README.rdoc
|
39
47
|
- Rakefile
|
40
48
|
- VERSION
|
49
|
+
- bin/filewatcher
|
41
50
|
- lib/filewatcher.rb
|
42
51
|
- test/helper.rb
|
43
52
|
- test/test_filewatcher.rb
|
@@ -46,26 +55,32 @@ homepage: http://github.com/thomasfl/filewatcher
|
|
46
55
|
licenses: []
|
47
56
|
|
48
57
|
post_install_message:
|
49
|
-
rdoc_options:
|
50
|
-
|
58
|
+
rdoc_options: []
|
59
|
+
|
51
60
|
require_paths:
|
52
61
|
- lib
|
53
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
54
64
|
requirements:
|
55
65
|
- - ">="
|
56
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
57
70
|
version: "0"
|
58
|
-
version:
|
59
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
60
73
|
requirements:
|
61
74
|
- - ">="
|
62
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
63
79
|
version: "0"
|
64
|
-
version:
|
65
80
|
requirements: []
|
66
81
|
|
67
82
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.3.
|
83
|
+
rubygems_version: 1.3.7
|
69
84
|
signing_key:
|
70
85
|
specification_version: 3
|
71
86
|
summary: Simple filewatcher.
|
data/.document
DELETED