filewatcher 0.5.4 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/filewatcher.rb +79 -138
- data/lib/filewatcher/cycles.rb +56 -0
- data/lib/filewatcher/snapshot.rb +65 -0
- data/lib/filewatcher/snapshots.rb +56 -0
- data/lib/filewatcher/spec_helper.rb +66 -0
- data/lib/filewatcher/spec_helper/watch_run.rb +74 -0
- data/lib/filewatcher/version.rb +5 -0
- data/spec/filewatcher/snapshot_spec.rb +67 -0
- data/spec/filewatcher/version_spec.rb +11 -0
- data/spec/filewatcher_spec.rb +289 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/spec_helper/ruby_watch_run.rb +82 -0
- metadata +92 -42
- data/LICENSE +0 -20
- data/README.md +0 -269
- data/Rakefile +0 -19
- data/bin/filewatcher +0 -168
- data/test/fixtures/file1.txt +0 -1
- data/test/fixtures/file2.txt +0 -1
- data/test/fixtures/file3.rb +0 -1
- data/test/fixtures/file4.rb +0 -1
- data/test/fixtures/subdir/file5.rb +0 -1
- data/test/fixtures/subdir/file6.rb +0 -1
- data/test/test_filewatcher.rb +0 -181
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
if ENV['CODECOV_TOKEN']
|
7
|
+
require 'codecov'
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
9
|
+
end
|
10
|
+
|
11
|
+
require_relative '../lib/filewatcher/spec_helper'
|
12
|
+
|
13
|
+
require_relative 'spec_helper/ruby_watch_run'
|
14
|
+
|
15
|
+
## For case when required from dumpers
|
16
|
+
if Object.const_defined?(:RSpec)
|
17
|
+
RSpec::Matchers.define :include_all_files do |expected|
|
18
|
+
match do |actual|
|
19
|
+
expected.all? { |file| actual.include? File.expand_path(file) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Filewatcher
|
4
|
+
module SpecHelper
|
5
|
+
class RubyWatchRun < WatchRun
|
6
|
+
attr_reader :filewatcher, :thread, :watched, :processed
|
7
|
+
|
8
|
+
def initialize(filewatcher:, **args)
|
9
|
+
super(**args)
|
10
|
+
@filewatcher = filewatcher
|
11
|
+
|
12
|
+
@mutex = Mutex.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def start
|
16
|
+
super
|
17
|
+
@thread = thread_initialize
|
18
|
+
# thread needs a chance to start
|
19
|
+
wait seconds: 1
|
20
|
+
wait do
|
21
|
+
keep_watching = filewatcher.keep_watching
|
22
|
+
debug "keep_watching = #{keep_watching}"
|
23
|
+
keep_watching
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
thread.exit
|
29
|
+
|
30
|
+
wait do
|
31
|
+
thread.stop?
|
32
|
+
end
|
33
|
+
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def wait(seconds: 1)
|
38
|
+
super seconds: seconds, interval: filewatcher.interval
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def make_changes
|
44
|
+
super
|
45
|
+
|
46
|
+
# Some OS, file systems and Ruby interpretators
|
47
|
+
# doesn't catch milliseconds of `File.mtime`
|
48
|
+
wait do
|
49
|
+
@mutex.synchronize do
|
50
|
+
debug "processed = #{processed}"
|
51
|
+
debug "processed.any? = #{processed.any?}"
|
52
|
+
processed.any?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def thread_initialize
|
58
|
+
@watched ||= 0
|
59
|
+
@processed = []
|
60
|
+
Thread.new { setup_filewatcher }
|
61
|
+
end
|
62
|
+
|
63
|
+
def setup_filewatcher
|
64
|
+
debug 'setup_filewatcher'
|
65
|
+
debug filewatcher.inspect
|
66
|
+
filewatcher.watch do |changes|
|
67
|
+
debug filewatcher.inspect
|
68
|
+
@mutex.synchronize do
|
69
|
+
debug "watch callback: changes = #{changes.inspect}"
|
70
|
+
increment_watched
|
71
|
+
@processed.push(changes)
|
72
|
+
# debug 'pushed to processed'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def increment_watched
|
78
|
+
@watched += 1
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
CHANGED
@@ -1,106 +1,156 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
|
-
|
8
|
+
- Alexander Popov
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-09-18 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: bundler
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
18
|
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '2.0'
|
20
|
-
type: :
|
21
|
+
type: :development
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
25
|
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
27
|
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: codecov
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.2.5
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.2.5
|
27
42
|
- !ruby/object:Gem::Dependency
|
28
43
|
name: rake
|
29
44
|
requirement: !ruby/object:Gem::Requirement
|
30
45
|
requirements:
|
31
46
|
- - "~>"
|
32
47
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
48
|
+
version: '13.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '13.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.8'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '3.8'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rubocop
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.91.0
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.91.0
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop-performance
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.5'
|
34
91
|
type: :development
|
35
92
|
prerelease: false
|
36
93
|
version_requirements: !ruby/object:Gem::Requirement
|
37
94
|
requirements:
|
38
95
|
- - "~>"
|
39
96
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
97
|
+
version: '1.5'
|
41
98
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
99
|
+
name: rubocop-rspec
|
43
100
|
requirement: !ruby/object:Gem::Requirement
|
44
101
|
requirements:
|
45
102
|
- - "~>"
|
46
103
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
104
|
+
version: '1.43'
|
48
105
|
type: :development
|
49
106
|
prerelease: false
|
50
107
|
version_requirements: !ruby/object:Gem::Requirement
|
51
108
|
requirements:
|
52
109
|
- - "~>"
|
53
110
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
55
|
-
description: Detect changes in
|
111
|
+
version: '1.43'
|
112
|
+
description: Detect changes in file system. Works anywhere.
|
56
113
|
email:
|
57
114
|
- thomas.flemming@gmail.com
|
58
|
-
|
59
|
-
|
115
|
+
- alex.wayfer@gmail.com
|
116
|
+
executables: []
|
60
117
|
extensions: []
|
61
118
|
extra_rdoc_files: []
|
62
119
|
files:
|
63
|
-
- LICENSE
|
64
|
-
- README.md
|
65
|
-
- Rakefile
|
66
|
-
- bin/filewatcher
|
67
120
|
- lib/filewatcher.rb
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
-
|
75
|
-
|
121
|
+
- lib/filewatcher/cycles.rb
|
122
|
+
- lib/filewatcher/snapshot.rb
|
123
|
+
- lib/filewatcher/snapshots.rb
|
124
|
+
- lib/filewatcher/spec_helper.rb
|
125
|
+
- lib/filewatcher/spec_helper/watch_run.rb
|
126
|
+
- lib/filewatcher/version.rb
|
127
|
+
- spec/filewatcher/snapshot_spec.rb
|
128
|
+
- spec/filewatcher/version_spec.rb
|
129
|
+
- spec/filewatcher_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/spec_helper/ruby_watch_run.rb
|
132
|
+
homepage: http://github.com/filewatcher/filewatcher
|
76
133
|
licenses:
|
77
134
|
- MIT
|
78
135
|
metadata: {}
|
79
|
-
post_install_message:
|
136
|
+
post_install_message:
|
80
137
|
rdoc_options: []
|
81
138
|
require_paths:
|
82
139
|
- lib
|
83
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
141
|
requirements:
|
85
|
-
- - "
|
142
|
+
- - "~>"
|
86
143
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
144
|
+
version: '2.4'
|
88
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
146
|
requirements:
|
90
|
-
- - "
|
147
|
+
- - ">"
|
91
148
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
149
|
+
version: 1.3.1
|
93
150
|
requirements: []
|
94
|
-
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
96
|
-
signing_key:
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.7.6.2
|
153
|
+
signing_key:
|
97
154
|
specification_version: 4
|
98
|
-
summary:
|
99
|
-
test_files:
|
100
|
-
- test/fixtures/file1.txt
|
101
|
-
- test/fixtures/file2.txt
|
102
|
-
- test/fixtures/file3.rb
|
103
|
-
- test/fixtures/file4.rb
|
104
|
-
- test/fixtures/subdir/file5.rb
|
105
|
-
- test/fixtures/subdir/file6.rb
|
106
|
-
- test/test_filewatcher.rb
|
155
|
+
summary: Lightweight filewatcher.
|
156
|
+
test_files: []
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 - 2014 Thomas Flemming
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,269 +0,0 @@
|
|
1
|
-
Filewatcher
|
2
|
-
===========
|
3
|
-
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/filewatcher.svg)](http://badge.fury.io/rb/filewatcher)
|
5
|
-
[![Build Status](https://secure.travis-ci.org/thomasfl/filewatcher.png?branch=master)](http://travis-ci.org/thomasfl/filewatcher)
|
6
|
-
[![Dependency Status](https://gemnasium.com/thomasfl/filewatcher.png?travis)](https://gemnasium.com/thomasfl/filewatcher)
|
7
|
-
[![Code Climate](https://codeclimate.com/github/thomasfl/filewatcher.png)](https://codeclimate.com/github/thomasfl/filewatcher)
|
8
|
-
|
9
|
-
Lightweight filewatcher weighing less than 200 LoC. No dependencies or platform specific code. Works everywhere. Monitors changes in the filesystem by polling. Has no config files. When running filewatcher from the command line, you specify which files to monitor and what action to perform on updates.
|
10
|
-
|
11
|
-
For example to search recursively for javascript files and run jshint when a file is updated, added, renamed or deleted:
|
12
|
-
|
13
|
-
Linux/OSX:
|
14
|
-
|
15
|
-
$ filewatcher '**/*.js' 'jshint $FILENAME'
|
16
|
-
|
17
|
-
In Windows:
|
18
|
-
|
19
|
-
> filewatcher "**/*.js" "jshint %FILENAME%"
|
20
|
-
|
21
|
-
Install
|
22
|
-
-------
|
23
|
-
|
24
|
-
Needs Ruby and Rubygems:
|
25
|
-
|
26
|
-
$ [sudo] gem install filewatcher
|
27
|
-
|
28
|
-
Command line utility
|
29
|
-
--------------------
|
30
|
-
|
31
|
-
Filewatcher scans the filesystem and execute shell commands when files are
|
32
|
-
updated, added, renamed or deleted.
|
33
|
-
|
34
|
-
Usage:
|
35
|
-
filewatcher [--restart][--list][--dontwait] "<filename>" "<shell command>"
|
36
|
-
|
37
|
-
Where
|
38
|
-
filename: filename(s) to scan.
|
39
|
-
shell command: shell command to execute when a file is changed
|
40
|
-
|
41
|
-
Examples
|
42
|
-
--------
|
43
|
-
|
44
|
-
Run the echo command when the file myfile is changed:
|
45
|
-
|
46
|
-
$ filewatcher "myfile" "echo 'myfile has changed'"
|
47
|
-
|
48
|
-
Run any javascript in the current directory when it is updated in Windows
|
49
|
-
Powershell:
|
50
|
-
|
51
|
-
> filewatcher *.js "node %FILENAME%"
|
52
|
-
|
53
|
-
In Linux/OSX:
|
54
|
-
|
55
|
-
$ filewatcher *.js 'node $FILENAME'
|
56
|
-
|
57
|
-
Place filenames or filenames in quotes to use ruby filename globbing instead
|
58
|
-
of shell filename globbing. This will make filewatcher look for files in
|
59
|
-
subdirectories too. To watch all javascript files in subdirectories in Windows:
|
60
|
-
|
61
|
-
> filewatcher "**/*.js" "node %FILENAME%"
|
62
|
-
|
63
|
-
In Linux/OSX:
|
64
|
-
|
65
|
-
> filewatcher '**/*.js' 'node $FILENAME'
|
66
|
-
|
67
|
-
Try to run the updated file as a script when it is updated by using the
|
68
|
-
--exec/-e option. Works with files with file extensions that looks like a
|
69
|
-
python, ruby, perl, php, javascript or awk script.
|
70
|
-
|
71
|
-
$ filewatcher -e *.rb
|
72
|
-
|
73
|
-
Print a list of all files matching *.css first and then output the filename
|
74
|
-
when a file is beeing updated by using the --list/-l option:
|
75
|
-
|
76
|
-
$ filewatcher -l '**/*.css' 'echo file: $FILENAME'
|
77
|
-
|
78
|
-
Watch the "src" and "test" folders recursively, and run test when the
|
79
|
-
filesystem gets updated:
|
80
|
-
|
81
|
-
$ filewatcher "src test" "ruby test/test_suite.rb"
|
82
|
-
|
83
|
-
Restart long running commands
|
84
|
-
-----------------------------
|
85
|
-
|
86
|
-
The `--restart` option kills the command if it's still running when a filesystem change happens. Can be used to restart locally running webservers on updates, or kill long running tests and restart on updates. This option often makes filewatcher faster in general. To not wait for tests to finish:
|
87
|
-
|
88
|
-
$ filewatcher --restart "**/*.rb" "rake test"
|
89
|
-
|
90
|
-
The `--dontwait` option starts the command on startup without waiting for filesystem updates. To start a webserver and have it automatically restart when html files are updated:
|
91
|
-
|
92
|
-
$ filewatcher --restart --dontwait "**/*.html" "python -m SimpleHTTPServer"
|
93
|
-
|
94
|
-
Available enviroment variables
|
95
|
-
------------------------------
|
96
|
-
|
97
|
-
The environment variable $FILENAME is available in the shell command argument.
|
98
|
-
On unix like systems the command has to be enclosed in single quotes. To run
|
99
|
-
node whenever a javascript file is updated:
|
100
|
-
|
101
|
-
$ filewatcher *.js 'node $FILENAME'
|
102
|
-
|
103
|
-
Environment variables available from the command string:
|
104
|
-
|
105
|
-
BASENAME File basename.
|
106
|
-
FILENAME Relative filename.
|
107
|
-
ABSOLUTE_FILENAME Asolute filename.
|
108
|
-
RELATIVE_FILENAME Same as FILENAME but starts with "./"
|
109
|
-
EVENT Event type. Is either 'changed', 'delete' or 'new'.
|
110
|
-
DIRNAME Absolute directory name.
|
111
|
-
|
112
|
-
Command line options
|
113
|
-
--------------------
|
114
|
-
|
115
|
-
Useful command line options:
|
116
|
-
|
117
|
-
--list, -l: Print name of matching files on startup
|
118
|
-
--restart, -r: Run command in separate fork and kill it on filesystem updates
|
119
|
-
--dontwait, -d: Run the command before any filesystem updates
|
120
|
-
--spinner, -s: Display an animated spinner while scanning
|
121
|
-
|
122
|
-
Other command line options:
|
123
|
-
|
124
|
-
--version, -v: Print version and exit
|
125
|
-
--help, -h: Show this message
|
126
|
-
--interval, -i <f>: Interval in seconds to scan filesystem. Defaults to 0.5 seconds.
|
127
|
-
--exec, -e: Execute file as a script when file is updated
|
128
|
-
--include, -n <s>: Include files (default: *)
|
129
|
-
--exclude, -x <s>: Exclude file(s) matching (default: "")
|
130
|
-
|
131
|
-
Ruby API
|
132
|
-
--------
|
133
|
-
|
134
|
-
Watch a list of files and directories:
|
135
|
-
|
136
|
-
require 'filewatcher'
|
137
|
-
|
138
|
-
FileWatcher.new(["lib/", "Rakefile"]).watch do |filename|
|
139
|
-
puts "Changed " + filename
|
140
|
-
end
|
141
|
-
|
142
|
-
Watch a single directory, for changes in all files and subdirectories:
|
143
|
-
|
144
|
-
FileWatcher.new("lib/").watch do |filename|
|
145
|
-
...
|
146
|
-
end
|
147
|
-
|
148
|
-
Notice that the previous is equivalent to the following:
|
149
|
-
|
150
|
-
FileWatcher.new("lib/**/*").watch do |filename|
|
151
|
-
...
|
152
|
-
end
|
153
|
-
|
154
|
-
Watch files and dirs in the given directory - and not in subdirectories:
|
155
|
-
|
156
|
-
FileWatcher.new("lib/*").watch do |filename|
|
157
|
-
...
|
158
|
-
end
|
159
|
-
|
160
|
-
Watch an absolute directory:
|
161
|
-
|
162
|
-
FileWatcher.new("/tmp/foo").watch do |filename|
|
163
|
-
...
|
164
|
-
end
|
165
|
-
|
166
|
-
To detect if a file is updated, added or deleted:
|
167
|
-
|
168
|
-
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
169
|
-
if(event == :changed)
|
170
|
-
puts "File updated: " + filename
|
171
|
-
end
|
172
|
-
if(event == :delete)
|
173
|
-
puts "File deleted: " + filename
|
174
|
-
end
|
175
|
-
if(event == :new)
|
176
|
-
puts "Added file: " + filename
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
When a file is renamed it is detected as a new file followed by a file deletion.
|
181
|
-
|
182
|
-
The API takes some of the same options as the command line interface. To watch all files recursively except files that matches *.rb, display a spinner and only wait for 0.1 seconds between each scan:
|
183
|
-
|
184
|
-
FileWatcher.new('**/*.*', exclude: '**/*.rb', spinner: true, interval: 0.1).watch() do |filename|
|
185
|
-
puts filename
|
186
|
-
end
|
187
|
-
|
188
|
-
To do the same from the command line, use the same options:
|
189
|
-
|
190
|
-
$ filewatcher '**/*.*' --exclude '**/*.rb' --spinner --interval 0.1 'echo $FILENAME'
|
191
|
-
|
192
|
-
Use patterns to match filenames in current directory and subdirectories. The
|
193
|
-
pattern is not a regular expression; instead it follows rules similar to shell
|
194
|
-
filename globbing. See Ruby
|
195
|
-
[documentation](http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch)
|
196
|
-
for syntax.
|
197
|
-
|
198
|
-
FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
|
199
|
-
puts "Updated " + filename
|
200
|
-
end
|
201
|
-
|
202
|
-
Start, pause, resume, stop, and finalize a running watch. This is particularly
|
203
|
-
useful when the update block takes a while to process each file (eg. sending
|
204
|
-
over the network)
|
205
|
-
|
206
|
-
filewatcher = FileWatcher.new(["*.rb"])
|
207
|
-
thread = Thread.new(filewatcher){|fw| fw.watch{|f| puts "Updated " + f}}
|
208
|
-
...
|
209
|
-
filewatcher.pause # block stops responding to filesystem changes
|
210
|
-
filewatcher.finalize # Ensure all filesystem changes made prior to
|
211
|
-
# pausing are handled.
|
212
|
-
...
|
213
|
-
filewatcher.resume # block begins responding again, but is not given
|
214
|
-
# changes made between #pause_watch and
|
215
|
-
# #resume_watch
|
216
|
-
...
|
217
|
-
filewatcher.end # block stops responding to filesystem changes
|
218
|
-
# and takes a final snapshot of the filesystem
|
219
|
-
thread.join
|
220
|
-
|
221
|
-
filewatcher.finalize # Ensure all filesystem changes made prior to
|
222
|
-
# ending the watch are handled.
|
223
|
-
|
224
|
-
If basename, relative filename or absolute filename is necessary use the standard lib 'pathname' like this:
|
225
|
-
|
226
|
-
require 'pathname'
|
227
|
-
|
228
|
-
FileWatcher.new(["**/*.*"]).watch() do |filename|
|
229
|
-
path = Pathname.new(filename)
|
230
|
-
puys "Basename : " + path.basename.to_s
|
231
|
-
puts "Relative filename: " + File.join(Pathname.new('.').to_s, path.to_s)
|
232
|
-
puts "Absolute filename: " + File.join(Pathname.new('.').realpath.to_s, path.to_s)
|
233
|
-
end
|
234
|
-
|
235
|
-
The filewatcher library is a single file with 180 LOC (including comments)
|
236
|
-
with no dependencies.
|
237
|
-
|
238
|
-
Changelog
|
239
|
-
---------
|
240
|
-
* 0.5.3 Exclude files. More environment variables. Options in ruby api.
|
241
|
-
* 0.5.2 Start, stop and finalize API.
|
242
|
-
* 0.5.1 Kill and restart long running command with --restart option.
|
243
|
-
|
244
|
-
Credits
|
245
|
-
-------
|
246
|
-
This project would not be where it is today without the generous help provided by people reporting issues and these contributors:
|
247
|
-
|
248
|
-
* Penn Taylor: Spinner displayed in the terminal and Start, pause, resume, stop, and finalize a running watch.
|
249
|
-
|
250
|
-
* Franco Leonardo Bulgarelli: Support for absolute and globbed paths by https://github.com/flbulgarelli
|
251
|
-
|
252
|
-
* Kristoffer Roupé https://github.com/kitofr Command line globbing by
|
253
|
-
|
254
|
-
This gem was initially inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-file-changes-with-ruby
|
255
|
-
|
256
|
-
Note on Patches/Pull Requests
|
257
|
-
-----------------------------
|
258
|
-
|
259
|
-
* Fork the project.
|
260
|
-
* Make your feature addition or bug fix.
|
261
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
262
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
263
|
-
* Send me a pull request. Bonus points for topic branches.
|
264
|
-
|
265
|
-
|
266
|
-
Copyright
|
267
|
-
---------
|
268
|
-
|
269
|
-
Copyright (c) 2011 - 2015 Thomas Flemming. See LICENSE for details.
|