cuco 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +6 -3
- data/cuco.gemspec +2 -2
- data/lib/controller.rb +12 -1
- data/lib/version.rb +2 -1
- data/test/controller2_test.rb +59 -0
- data/test/controller_test.rb +9 -16
- data/test/coverage_test.rb +19 -0
- data/test/cuco_test.rb +16 -11
- data/test/test_helper.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5342bb409b3bd1e9febe557662bf308acc1ae727911401b4be2a0d0d8fb06c07
|
4
|
+
data.tar.gz: 4948f0decd177693378761e046875a2808d4af80cfd0b17d5166aedfa4fb326c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d0c34c445d0ac41e63589a8e240f2bf3b6fcdc3414b6f060009004b14bd720428a2c331637c8df9554ba73d824e76f25f54a52a9f245ca2f844abcf7a67e71e
|
7
|
+
data.tar.gz: 9a9a183c7ee4aff77eb749797792cb7b686d490453ab92c72b6a3f03ecc2c331c723c69e4fd74f1f6f3bac40e556267d848eaf57a6c1761d4b7352c94c5aa8bc
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cuco (0.1.
|
4
|
+
cuco (0.1.1)
|
5
5
|
listen
|
6
6
|
micro-optparse
|
7
7
|
|
@@ -85,7 +85,7 @@ GEM
|
|
85
85
|
psych (5.1.2)
|
86
86
|
stringio
|
87
87
|
racc (1.7.3)
|
88
|
-
rack (3.0.
|
88
|
+
rack (3.0.10)
|
89
89
|
rack-session (2.0.0)
|
90
90
|
rack (>= 3.0.0)
|
91
91
|
rack-test (2.1.0)
|
@@ -113,7 +113,7 @@ GEM
|
|
113
113
|
rb-fsevent (0.11.2)
|
114
114
|
rb-inotify (0.10.1)
|
115
115
|
ffi (~> 1.0)
|
116
|
-
rdoc (6.6.
|
116
|
+
rdoc (6.6.3.1)
|
117
117
|
psych (>= 4.0.0)
|
118
118
|
regexp_parser (2.9.0)
|
119
119
|
reline (0.4.3)
|
data/README.md
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/cuco.png)](http://badge.fury.io/rb/cuco)
|
4
4
|
[![GEM Downloads](https://img.shields.io/gem/dt/cuco?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/cuco)
|
5
|
+
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://choosealicense.com/licenses/mit/)
|
5
6
|
|
6
|
-
*Cuco*
|
7
|
+
*Cuco* watches files in a directory and take an action when they change.
|
7
8
|
|
8
9
|
*Cuco* is controlled by a user-supplied script file.
|
9
10
|
Intermixed "watch" commands specify what to do
|
@@ -38,7 +39,10 @@ $ cuco path/to/script/file
|
|
38
39
|
will monitor files in the current directory tree
|
39
40
|
and react to events on those files in accordance with the script.
|
40
41
|
|
41
|
-
## A simple example of a script file
|
42
|
+
## A simple example of a script file
|
43
|
+
|
44
|
+
This sample script is intended for testing purposes with Minitest.
|
45
|
+
*md* is the match-data (see Ruby regular expressions).
|
42
46
|
|
43
47
|
```ruby
|
44
48
|
watch( 'test/.*_test\.rb$' ) { |md| run_it(md[0]) }
|
@@ -59,7 +63,6 @@ Scripts are pure Ruby.
|
|
59
63
|
Intermixed are "watch" rules that match observed files to an action.
|
60
64
|
The matching is achieved by a pattern (a regular expression) parameter.
|
61
65
|
The action is specified by a block (see above sample).
|
62
|
-
*md* is the match-data.
|
63
66
|
|
64
67
|
Updates to script files are picked up on the fly (no need to restart *cuco*)
|
65
68
|
so experimenting is painless.
|
data/cuco.gemspec
CHANGED
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
.split("\n").map { |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
18
|
|
19
|
-
s.
|
20
|
-
s.
|
19
|
+
s.add_runtime_dependency "micro-optparse"
|
20
|
+
s.add_runtime_dependency "listen"
|
21
21
|
|
22
22
|
s.add_development_dependency "minitest"
|
23
23
|
s.add_development_dependency "rake"
|
data/lib/controller.rb
CHANGED
@@ -40,7 +40,18 @@ class Controller
|
|
40
40
|
|
41
41
|
def file_run(pattern, type = nil)
|
42
42
|
puts "*** file_run(#{pattern}, #{type})" if debug
|
43
|
-
|
43
|
+
rules = find_rules(pattern, type)
|
44
|
+
rules.each { |rule| match_run(rule, pattern) }
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def find_rules(pattern, type)
|
50
|
+
puts "*** find_rules(#{pattern}, #{type})" if debug
|
51
|
+
G.script.__rules.reverse.select { |rule|
|
52
|
+
pattern.match(rule.pattern) &&
|
53
|
+
(rule.event_type.nil? || rule.event_type == type)
|
54
|
+
}
|
44
55
|
end
|
45
56
|
|
46
57
|
def match_run(rule, pattern)
|
data/lib/version.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class R
|
4
|
+
class << self
|
5
|
+
attr_accessor :acc
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Controller do
|
10
|
+
let(:cntrl) { Controller.instance }
|
11
|
+
|
12
|
+
def setup
|
13
|
+
R.acc = ""
|
14
|
+
G.init({}, [])
|
15
|
+
G.script = Script.new <<~EOS
|
16
|
+
watch('file') { R.acc << "n" }
|
17
|
+
watch('file', :added) { R.acc << "a" }
|
18
|
+
watch('file', :modified) { R.acc << "m" }
|
19
|
+
EOS
|
20
|
+
end
|
21
|
+
|
22
|
+
def teardown
|
23
|
+
cntrl.stop
|
24
|
+
end
|
25
|
+
|
26
|
+
it "fails with unknown what pattern" do
|
27
|
+
cntrl.file_run("fail", nil)
|
28
|
+
assert_equal "", R.acc
|
29
|
+
end
|
30
|
+
|
31
|
+
it "considers event_type nil" do
|
32
|
+
check nil, "n"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "considers event_type :added" do
|
36
|
+
check :added, "an"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "considers event_type :modified" do
|
40
|
+
check :modified, "mn"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "receives a matchdata" do
|
44
|
+
G.script = Script.new "watch('ab(.)') { |m|
|
45
|
+
R.acc << m[0]
|
46
|
+
R.acc << m[1]
|
47
|
+
}"
|
48
|
+
|
49
|
+
cntrl.file_run("abc", nil)
|
50
|
+
assert_equal "abcc", R.acc
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def check(type, expected)
|
56
|
+
cntrl.file_run("file", type)
|
57
|
+
assert_equal expected, R.acc
|
58
|
+
end
|
59
|
+
end
|
data/test/controller_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
describe Controller do
|
4
|
-
let(:
|
4
|
+
let(:cntrl) { Controller.instance }
|
5
5
|
let(:regexp) { '.*\.rb' }
|
6
6
|
|
7
7
|
def setup
|
@@ -9,44 +9,37 @@ describe Controller do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def teardown
|
12
|
-
|
12
|
+
cntrl.stop
|
13
13
|
end
|
14
14
|
|
15
15
|
it "stops" do
|
16
|
-
|
17
|
-
assert_nil
|
16
|
+
cntrl.stop
|
17
|
+
assert_nil cntrl.listener
|
18
18
|
end
|
19
19
|
|
20
20
|
it "runs" do
|
21
21
|
assert_raises(Timeout::Error) do
|
22
|
-
Timeout.timeout(0.1) {
|
22
|
+
Timeout.timeout(0.1) { cntrl.run }
|
23
23
|
end
|
24
24
|
|
25
|
-
assert
|
25
|
+
assert cntrl.listener
|
26
26
|
end
|
27
27
|
|
28
28
|
it "read .watchr" do
|
29
29
|
assert_raises(Timeout::Error) do
|
30
|
-
Timeout.timeout(0.1) {
|
30
|
+
Timeout.timeout(0.1) { cntrl.run }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
it "run" do
|
35
35
|
G.script = Script.new "watch('#{regexp}') { raise IOError }"
|
36
36
|
|
37
|
-
assert_raises(IOError) {
|
37
|
+
assert_raises(IOError) { cntrl.file_run "a.rb" }
|
38
38
|
end
|
39
39
|
|
40
40
|
it "does not run" do
|
41
41
|
G.script = Script.new "watch('#{regexp}') { raise IOError }"
|
42
42
|
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
it "receives a matchdata" do
|
47
|
-
G.script = Script.new "watch('ab(.)') { |m| [m[0], m[1]] }"
|
48
|
-
|
49
|
-
rule = G.script.__rules.last
|
50
|
-
assert_equal ["abc", "c"], cuco.match_run(rule, "abc")
|
43
|
+
cntrl.file_run "a.no"
|
51
44
|
end
|
52
45
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe "Coverage" do
|
4
|
+
let(:cntrl) { Controller.instance }
|
5
|
+
|
6
|
+
def setup
|
7
|
+
G.init({}, [])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "coverage run files" do
|
11
|
+
names = []
|
12
|
+
cntrl.run_files(names, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "coverage run files script" do
|
16
|
+
names = [G.scriptname]
|
17
|
+
cntrl.run_files(names, nil)
|
18
|
+
end
|
19
|
+
end
|
data/test/cuco_test.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
describe Cuco do
|
4
|
+
def setup
|
5
|
+
G.init({}, [])
|
6
|
+
end
|
7
|
+
|
4
8
|
it "usage" do
|
5
9
|
out, _err = capture_io do
|
6
10
|
puts `bin/cuco -h`
|
@@ -9,21 +13,22 @@ describe Cuco do
|
|
9
13
|
assert_match(/Usage/, out)
|
10
14
|
end
|
11
15
|
|
16
|
+
it "coverage G.print " do
|
17
|
+
out, err = capture_io do
|
18
|
+
G.print
|
19
|
+
end
|
20
|
+
|
21
|
+
assert out
|
22
|
+
assert_equal "", err
|
23
|
+
assert_match(/scriptname/, out)
|
24
|
+
assert_match(/.watchr/, out)
|
25
|
+
assert_match(/pwd/, out)
|
26
|
+
end
|
27
|
+
|
12
28
|
it "options" do
|
13
29
|
options = {opt: 1234}
|
14
30
|
G.init options, []
|
15
31
|
|
16
32
|
assert_equal options, G.options
|
17
33
|
end
|
18
|
-
|
19
|
-
# it "coverage options debug" do
|
20
|
-
# out, _err = capture_io do
|
21
|
-
# puts `bin/cuco -d`
|
22
|
-
# Timeout::timeout(0.1) { puts `bin/cuco -d` }
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# assert_match(/:debug=>true/, out)
|
26
|
-
# assert_match(/scriptname <.watchr>/, out)
|
27
|
-
# assert_match(/pwd/, out)
|
28
|
-
# end
|
29
34
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dittmar Krall
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: micro-optparse
|
@@ -88,7 +88,9 @@ files:
|
|
88
88
|
- lib/cuco.rb
|
89
89
|
- lib/script.rb
|
90
90
|
- lib/version.rb
|
91
|
+
- test/controller2_test.rb
|
91
92
|
- test/controller_test.rb
|
93
|
+
- test/coverage_test.rb
|
92
94
|
- test/cuco_test.rb
|
93
95
|
- test/script_test.rb
|
94
96
|
- test/test_helper.rb
|