cuco 0.0.7
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.
- checksums.yaml +7 -0
- data/.github/workflows/rake.yml +24 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.watchr +9 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +184 -0
- data/LICENSE-MIT +22 -0
- data/README.md +77 -0
- data/Rakefile +11 -0
- data/bin/cuco +18 -0
- data/cuco.gemspec +24 -0
- data/lib/controller.rb +52 -0
- data/lib/cuco.rb +1 -0
- data/lib/script.rb +39 -0
- data/lib/version.rb +6 -0
- data/test/controller_test.rb +52 -0
- data/test/cuco_test.rb +31 -0
- data/test/script_test.rb +53 -0
- data/test/test_helper.rb +12 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: df5d2e1075b623db0450271a4535f241da3946afc2b76091653a0a5b434d3a97
|
4
|
+
data.tar.gz: 58c75efde02ac4b5b2637d6cc80b2e6a76589b477d7c162a84e7e6fe11aa8df8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 83a0f2b95909e51d131b8dcdf6c67cffbc7ccd9405da61bb75c0599a4f77eeef0b31425a81bc930d215524f93ddf32666b8cedcf750b6f867d388f6a95ba5308
|
7
|
+
data.tar.gz: 26245ecc48a0d9e4f7c19890e683944c4f2c99fb4a12840cb6e440688069583c3c74c61726bf7ac1de490715bb4e6cdd7e748f95d57e4bb5835128bc1c7c65e4
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
2
|
+
name: Rake
|
3
|
+
|
4
|
+
on: [push]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
os: [ubuntu-latest]
|
12
|
+
ruby: ["3.0", 3.3]
|
13
|
+
test_command: ["bundle exec rake test"]
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
- name: Set up Ruby
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby_version }}
|
22
|
+
bundler-cache: true
|
23
|
+
- name: Build and test with Rake
|
24
|
+
run: bundle exec rake
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rails-7.1
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.3.0
|
data/.watchr
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
watch('test/.*_test\.rb$') { |md| run_it(md[0]) }
|
2
|
+
watch('lib/(.*)\.rb$') { |md| run_it("test/#{md[1]}_test.rb") }
|
3
|
+
|
4
|
+
def run_it(file)
|
5
|
+
system %(bundle exec ruby -I test #{file})
|
6
|
+
end
|
7
|
+
|
8
|
+
Signal.trap("QUIT") { system("bundle exec rake") } # Ctrl-\ or ctrl-4
|
9
|
+
Signal.trap("INT") { abort("Interrupted\n") } # Ctrl-C
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cuco (0.0.7)
|
5
|
+
listen
|
6
|
+
micro-optparse
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (7.1.3.2)
|
12
|
+
actionview (= 7.1.3.2)
|
13
|
+
activesupport (= 7.1.3.2)
|
14
|
+
nokogiri (>= 1.8.5)
|
15
|
+
racc
|
16
|
+
rack (>= 2.2.4)
|
17
|
+
rack-session (>= 1.0.1)
|
18
|
+
rack-test (>= 0.6.3)
|
19
|
+
rails-dom-testing (~> 2.2)
|
20
|
+
rails-html-sanitizer (~> 1.6)
|
21
|
+
actionview (7.1.3.2)
|
22
|
+
activesupport (= 7.1.3.2)
|
23
|
+
builder (~> 3.1)
|
24
|
+
erubi (~> 1.11)
|
25
|
+
rails-dom-testing (~> 2.2)
|
26
|
+
rails-html-sanitizer (~> 1.6)
|
27
|
+
activesupport (7.1.3.2)
|
28
|
+
base64
|
29
|
+
bigdecimal
|
30
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
31
|
+
connection_pool (>= 2.2.5)
|
32
|
+
drb
|
33
|
+
i18n (>= 1.6, < 2)
|
34
|
+
minitest (>= 5.1)
|
35
|
+
mutex_m
|
36
|
+
tzinfo (~> 2.0)
|
37
|
+
ast (2.4.2)
|
38
|
+
base64 (0.2.0)
|
39
|
+
bigdecimal (3.1.7)
|
40
|
+
builder (3.2.4)
|
41
|
+
concurrent-ruby (1.2.3)
|
42
|
+
connection_pool (2.4.1)
|
43
|
+
crass (1.0.6)
|
44
|
+
docile (1.4.0)
|
45
|
+
drb (2.2.1)
|
46
|
+
erubi (1.12.0)
|
47
|
+
ffi (1.16.3)
|
48
|
+
i18n (1.14.4)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
io-console (0.7.2)
|
51
|
+
irb (1.12.0)
|
52
|
+
rdoc
|
53
|
+
reline (>= 0.4.2)
|
54
|
+
json (2.7.1)
|
55
|
+
language_server-protocol (3.17.0.3)
|
56
|
+
lint_roller (1.1.0)
|
57
|
+
listen (3.9.0)
|
58
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
59
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
60
|
+
loofah (2.22.0)
|
61
|
+
crass (~> 1.0.2)
|
62
|
+
nokogiri (>= 1.12.0)
|
63
|
+
micro-optparse (1.2.1)
|
64
|
+
minitest (5.22.3)
|
65
|
+
minitest-spec-rails (7.2.0)
|
66
|
+
minitest (>= 5.0)
|
67
|
+
railties (>= 4.1)
|
68
|
+
mutex_m (0.2.0)
|
69
|
+
nokogiri (1.16.3-aarch64-linux)
|
70
|
+
racc (~> 1.4)
|
71
|
+
nokogiri (1.16.3-arm-linux)
|
72
|
+
racc (~> 1.4)
|
73
|
+
nokogiri (1.16.3-arm64-darwin)
|
74
|
+
racc (~> 1.4)
|
75
|
+
nokogiri (1.16.3-x86-linux)
|
76
|
+
racc (~> 1.4)
|
77
|
+
nokogiri (1.16.3-x86_64-darwin)
|
78
|
+
racc (~> 1.4)
|
79
|
+
nokogiri (1.16.3-x86_64-linux)
|
80
|
+
racc (~> 1.4)
|
81
|
+
parallel (1.24.0)
|
82
|
+
parser (3.3.0.5)
|
83
|
+
ast (~> 2.4.1)
|
84
|
+
racc
|
85
|
+
psych (5.1.2)
|
86
|
+
stringio
|
87
|
+
racc (1.7.3)
|
88
|
+
rack (3.0.9.1)
|
89
|
+
rack-session (2.0.0)
|
90
|
+
rack (>= 3.0.0)
|
91
|
+
rack-test (2.1.0)
|
92
|
+
rack (>= 1.3)
|
93
|
+
rackup (2.1.0)
|
94
|
+
rack (>= 3)
|
95
|
+
webrick (~> 1.8)
|
96
|
+
rails-dom-testing (2.2.0)
|
97
|
+
activesupport (>= 5.0.0)
|
98
|
+
minitest
|
99
|
+
nokogiri (>= 1.6)
|
100
|
+
rails-html-sanitizer (1.6.0)
|
101
|
+
loofah (~> 2.21)
|
102
|
+
nokogiri (~> 1.14)
|
103
|
+
railties (7.1.3.2)
|
104
|
+
actionpack (= 7.1.3.2)
|
105
|
+
activesupport (= 7.1.3.2)
|
106
|
+
irb
|
107
|
+
rackup (>= 1.0.0)
|
108
|
+
rake (>= 12.2)
|
109
|
+
thor (~> 1.0, >= 1.2.2)
|
110
|
+
zeitwerk (~> 2.6)
|
111
|
+
rainbow (3.1.1)
|
112
|
+
rake (13.1.0)
|
113
|
+
rb-fsevent (0.11.2)
|
114
|
+
rb-inotify (0.10.1)
|
115
|
+
ffi (~> 1.0)
|
116
|
+
rdoc (6.6.2)
|
117
|
+
psych (>= 4.0.0)
|
118
|
+
regexp_parser (2.9.0)
|
119
|
+
reline (0.4.3)
|
120
|
+
io-console (~> 0.5)
|
121
|
+
rexml (3.2.6)
|
122
|
+
ricecream (0.2.1)
|
123
|
+
rubocop (1.62.1)
|
124
|
+
json (~> 2.3)
|
125
|
+
language_server-protocol (>= 3.17.0)
|
126
|
+
parallel (~> 1.10)
|
127
|
+
parser (>= 3.3.0.2)
|
128
|
+
rainbow (>= 2.2.2, < 4.0)
|
129
|
+
regexp_parser (>= 1.8, < 3.0)
|
130
|
+
rexml (>= 3.2.5, < 4.0)
|
131
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
132
|
+
ruby-progressbar (~> 1.7)
|
133
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
134
|
+
rubocop-ast (1.31.2)
|
135
|
+
parser (>= 3.3.0.4)
|
136
|
+
rubocop-performance (1.20.2)
|
137
|
+
rubocop (>= 1.48.1, < 2.0)
|
138
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
139
|
+
ruby-progressbar (1.13.0)
|
140
|
+
simplecov (0.22.0)
|
141
|
+
docile (~> 1.1)
|
142
|
+
simplecov-html (~> 0.11)
|
143
|
+
simplecov_json_formatter (~> 0.1)
|
144
|
+
simplecov-html (0.12.3)
|
145
|
+
simplecov_json_formatter (0.1.4)
|
146
|
+
standard (1.35.1)
|
147
|
+
language_server-protocol (~> 3.17.0.2)
|
148
|
+
lint_roller (~> 1.0)
|
149
|
+
rubocop (~> 1.62.0)
|
150
|
+
standard-custom (~> 1.0.0)
|
151
|
+
standard-performance (~> 1.3)
|
152
|
+
standard-custom (1.0.2)
|
153
|
+
lint_roller (~> 1.0)
|
154
|
+
rubocop (~> 1.50)
|
155
|
+
standard-performance (1.3.1)
|
156
|
+
lint_roller (~> 1.1)
|
157
|
+
rubocop-performance (~> 1.20.2)
|
158
|
+
stringio (3.1.0)
|
159
|
+
thor (1.3.1)
|
160
|
+
tzinfo (2.0.6)
|
161
|
+
concurrent-ruby (~> 1.0)
|
162
|
+
unicode-display_width (2.5.0)
|
163
|
+
webrick (1.8.1)
|
164
|
+
zeitwerk (2.6.13)
|
165
|
+
|
166
|
+
PLATFORMS
|
167
|
+
aarch64-linux
|
168
|
+
arm-linux
|
169
|
+
arm64-darwin
|
170
|
+
x86-linux
|
171
|
+
x86_64-darwin
|
172
|
+
x86_64-linux
|
173
|
+
|
174
|
+
DEPENDENCIES
|
175
|
+
cuco!
|
176
|
+
minitest
|
177
|
+
minitest-spec-rails
|
178
|
+
rake
|
179
|
+
ricecream
|
180
|
+
simplecov
|
181
|
+
standard
|
182
|
+
|
183
|
+
BUNDLED WITH
|
184
|
+
2.5.6
|
data/LICENSE-MIT
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Dittmar Krall (www.matiq.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Cuco
|
2
|
+
|
3
|
+
*Cuco* watch files in a directory and take an action when they change.
|
4
|
+
|
5
|
+
*Cuco* is controlled by a user-supplied script file.
|
6
|
+
Intermixed "watch" commands specify what to do
|
7
|
+
for the particular modified files.
|
8
|
+
|
9
|
+
*Cuco* is:
|
10
|
+
|
11
|
+
* Simple to use
|
12
|
+
* Highly flexible
|
13
|
+
* Evented ( uses gem listen )
|
14
|
+
* Portable ( Ruby )
|
15
|
+
|
16
|
+
Most importantly it is **agnostic** to:
|
17
|
+
|
18
|
+
* Test frameworks
|
19
|
+
* Web frameworks
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
$ gem install cuco
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
$ cuco # default script file is .watchr
|
31
|
+
Or
|
32
|
+
$ cuco path/to/script/file
|
33
|
+
```
|
34
|
+
|
35
|
+
will monitor files in the current directory tree
|
36
|
+
and react to events on those files in accordance with the script.
|
37
|
+
|
38
|
+
## A simple example of a script file (using Minitest):
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
watch( 'test/.*_test\.rb$' ) { |md| run_it(md[0]) }
|
42
|
+
watch( 'lib/(.*)\.rb$' ) { |md| run_it("test/#{md[1]}_test.rb") }
|
43
|
+
|
44
|
+
def run_it(file)
|
45
|
+
system %(bundle exec ruby -I test #{file})
|
46
|
+
end
|
47
|
+
|
48
|
+
Signal.trap("QUIT") { system("bundle exec rake") } # Ctrl-\ or ctrl-4
|
49
|
+
Signal.trap("INT") { abort("Interrupted\n") } # Ctrl-C
|
50
|
+
```
|
51
|
+
|
52
|
+
## Script
|
53
|
+
|
54
|
+
Scripts are pure Ruby.
|
55
|
+
|
56
|
+
Intermixed are "watch" rules that match observed files to an action.
|
57
|
+
The matching is achieved by a pattern (a regular expression) parameter.
|
58
|
+
The action is specified by a block (see above sample).
|
59
|
+
*md* is the match-data.
|
60
|
+
|
61
|
+
Updates to script files are picked up on the fly (no need to restart *cuco*)
|
62
|
+
so experimenting is painless.
|
63
|
+
|
64
|
+
It's easy to see why *cuco* is so flexible,
|
65
|
+
since the whole command is custom.
|
66
|
+
The above actions could just as easily call "jruby", "ruby --rubygems",
|
67
|
+
"ruby -I lib", etc. or any combination of these.
|
68
|
+
|
69
|
+
## Miscellaneous
|
70
|
+
|
71
|
+
*Cuco* is heavily inspired by:
|
72
|
+
|
73
|
+
* gem watchr
|
74
|
+
* gem observr (a follow-up of gem watchr)
|
75
|
+
|
76
|
+
Copyright (c) 2024 Dittmar Krall (www.matiq.com),
|
77
|
+
released under the [MIT license](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/cuco
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib/", __dir__)
|
4
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "version"
|
7
|
+
require "controller"
|
8
|
+
require "micro-optparse"
|
9
|
+
|
10
|
+
options = Parser.new do |p|
|
11
|
+
p.banner = "Usage: cuco [options] [.watchr] # a file watcher"
|
12
|
+
p.version = "cuco #{Cuco::VERSION}"
|
13
|
+
p.option :debug, "Debugging output", default: false
|
14
|
+
end.process!
|
15
|
+
|
16
|
+
cuco = Controller.instance
|
17
|
+
cuco.init(options, ARGV)
|
18
|
+
cuco.run
|
data/cuco.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path("../lib/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "cuco"
|
5
|
+
s.version = Cuco::VERSION
|
6
|
+
s.summary = "A file watcher"
|
7
|
+
s.description = "A simple and flexible file watcher"
|
8
|
+
|
9
|
+
s.authors = ["Dittmar Krall"]
|
10
|
+
s.email = "dittmar.krall@matiq.de"
|
11
|
+
s.homepage = "http://www.matiq.de"
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`
|
16
|
+
.split("\n").map { |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency "micro-optparse"
|
20
|
+
s.add_dependency "listen"
|
21
|
+
|
22
|
+
s.add_development_dependency "minitest"
|
23
|
+
s.add_development_dependency "rake"
|
24
|
+
end
|
data/lib/controller.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "listen"
|
2
|
+
require "singleton"
|
3
|
+
require "cuco"
|
4
|
+
require "script"
|
5
|
+
|
6
|
+
class Controller
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_reader :listener
|
10
|
+
attr_reader :options
|
11
|
+
attr_reader :pwd_size
|
12
|
+
attr_reader :script_name
|
13
|
+
attr_reader :script
|
14
|
+
|
15
|
+
def init(options, argv)
|
16
|
+
@options = options
|
17
|
+
@script_name = argv.first || ".watchr"
|
18
|
+
@pwd_size = Dir.pwd.size
|
19
|
+
|
20
|
+
if @options[:debug]
|
21
|
+
puts "options #{@options}"
|
22
|
+
puts "pwd <#{@pwd}>"
|
23
|
+
puts "script_name <#{@script_name}>"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
stop
|
29
|
+
@script = Script.new
|
30
|
+
@script.load_file(@script_name)
|
31
|
+
@listener = Listen.to(".") do |modified, added, removed|
|
32
|
+
run_files(modified, :modified)
|
33
|
+
run_files(added, :added)
|
34
|
+
end
|
35
|
+
|
36
|
+
@listener.start
|
37
|
+
sleep
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop
|
41
|
+
@listener&.stop
|
42
|
+
@script = nil
|
43
|
+
@listener = nil
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def run_files(files, type)
|
49
|
+
files.map! { |filename| filename[@pwd_size + 1..] }
|
50
|
+
files.each { |filename| @script.run(filename, type) }
|
51
|
+
end
|
52
|
+
end
|
data/lib/cuco.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Rule = Struct.new(:pattern, :event_type, :proc)
|
data/lib/script.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
class Script
|
2
|
+
attr_reader :__rules
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
reset
|
6
|
+
end
|
7
|
+
|
8
|
+
def load(str)
|
9
|
+
reset
|
10
|
+
instance_eval str
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_file(filename)
|
14
|
+
file_data = File.read(filename)
|
15
|
+
load file_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def watch(pattern, type = nil, &block)
|
19
|
+
@__rules << Rule.new(pattern, type, block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def match_run(rule, pattern)
|
23
|
+
md = pattern.match(rule.pattern)
|
24
|
+
rule.proc.call(md) if md
|
25
|
+
end
|
26
|
+
|
27
|
+
def run(pattern, type = nil)
|
28
|
+
@__rules.select { |rule| match_run(rule, pattern) }
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def reset
|
34
|
+
@__rules = []
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
|
39
|
+
# $ sudo sysctl -p
|
data/lib/version.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "timeout"
|
3
|
+
require "controller"
|
4
|
+
require "script"
|
5
|
+
|
6
|
+
describe Controller do
|
7
|
+
let(:options) { {} }
|
8
|
+
let(:cuco) { Controller.instance }
|
9
|
+
let(:script) { Script.new }
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
cuco.stop
|
13
|
+
end
|
14
|
+
|
15
|
+
it "stops" do
|
16
|
+
cuco.stop
|
17
|
+
assert_nil cuco.listener
|
18
|
+
end
|
19
|
+
|
20
|
+
it "initializes" do
|
21
|
+
cuco.init(options, [])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "runs" do
|
25
|
+
cuco.init(options, [])
|
26
|
+
assert_raises(Timeout::Error) do
|
27
|
+
Timeout.timeout(0.1) { cuco.run }
|
28
|
+
end
|
29
|
+
|
30
|
+
assert cuco.listener
|
31
|
+
end
|
32
|
+
|
33
|
+
it "read .watchr" do
|
34
|
+
filename = ".watchr"
|
35
|
+
|
36
|
+
script.load_file filename
|
37
|
+
assert_equal 2, script.__rules.size
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def test_files
|
43
|
+
dir = File.join(Dir.pwd, "test", "files")
|
44
|
+
files = find_files_in(dir)
|
45
|
+
files.collect { |file| File.join(dir, file) }
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_files_in(dir)
|
49
|
+
entries = Dir.entries(dir)
|
50
|
+
entries.reject { |entry| File.directory?(entry) }
|
51
|
+
end
|
52
|
+
end
|
data/test/cuco_test.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Cuco do
|
4
|
+
let(:cuco) { Controller.instance }
|
5
|
+
|
6
|
+
it "usage" do
|
7
|
+
out, _err = capture_io do
|
8
|
+
puts `bin/cuco -h`
|
9
|
+
end
|
10
|
+
|
11
|
+
assert_match(/Usage/, out)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "options" do
|
15
|
+
options = {opt: 1234}
|
16
|
+
cuco.init(options, [])
|
17
|
+
|
18
|
+
assert_equal options, cuco.options
|
19
|
+
end
|
20
|
+
|
21
|
+
# it "coverage options debug" do
|
22
|
+
# out, _err = capture_io do
|
23
|
+
# puts `bin/cuco -d`
|
24
|
+
# # Timeout::timeout(0.1) { puts `bin/cuco -d` }
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# assert_match(/:debug=>true/, out)
|
28
|
+
# assert_match(/script <.watchr>/, out)
|
29
|
+
# assert_match(/pwd/, out)
|
30
|
+
# end
|
31
|
+
end
|
data/test/script_test.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "script"
|
3
|
+
|
4
|
+
describe Script do
|
5
|
+
let(:script) { Script.new }
|
6
|
+
|
7
|
+
it "checks script instance" do
|
8
|
+
assert script.instance_of?(Script)
|
9
|
+
assert script.respond_to?(:__rules)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has no watcher" do
|
13
|
+
script.load "n = 123"
|
14
|
+
assert_equal 0, script.__rules.size
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has one watcher" do
|
18
|
+
script.load "n = 456; watch('.rb') { }"
|
19
|
+
|
20
|
+
assert_equal 1, script.__rules.size
|
21
|
+
end
|
22
|
+
|
23
|
+
it "calls a watcher" do
|
24
|
+
pattern = '\.rb'
|
25
|
+
value = 123
|
26
|
+
# script.load "n = value; watch(pattern) { n }" # WHAT??
|
27
|
+
script.load "n = #{value}; watch('#{pattern}') { n }"
|
28
|
+
|
29
|
+
rule = script.__rules.last
|
30
|
+
assert_equal [pattern, value], [rule.pattern, rule.proc.call]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "receives a matchdata" do
|
34
|
+
script.load "watch('ab(.)') { |m| [m[0], m[1]] }"
|
35
|
+
|
36
|
+
rule = script.__rules.last
|
37
|
+
assert_equal ["abc", "c"], script.match_run(rule, "abc")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "run" do
|
41
|
+
pattern = '.*\.rb'
|
42
|
+
script.load "watch('#{pattern}') { raise IOError }"
|
43
|
+
|
44
|
+
assert_raises(IOError) { script.run "a.rb" }
|
45
|
+
end
|
46
|
+
|
47
|
+
it "does not run" do
|
48
|
+
pattern = '.*\.rb'
|
49
|
+
script.load "watch('#{pattern}') { raise IOError }"
|
50
|
+
|
51
|
+
script.run "a.no" # no exception
|
52
|
+
end
|
53
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cuco
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dittmar Krall
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: micro-optparse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: listen
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A simple and flexible file watcher
|
70
|
+
email: dittmar.krall@matiq.de
|
71
|
+
executables:
|
72
|
+
- cuco
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".github/workflows/rake.yml"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".watchr"
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE-MIT
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/cuco
|
86
|
+
- cuco.gemspec
|
87
|
+
- lib/controller.rb
|
88
|
+
- lib/cuco.rb
|
89
|
+
- lib/script.rb
|
90
|
+
- lib/version.rb
|
91
|
+
- test/controller_test.rb
|
92
|
+
- test/cuco_test.rb
|
93
|
+
- test/script_test.rb
|
94
|
+
- test/test_helper.rb
|
95
|
+
homepage: http://www.matiq.de
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubygems_version: 3.5.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: A file watcher
|
118
|
+
test_files: []
|