cuco 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9593da558bc5f53a9b517a7e82a3e9d3682f0da1883f802e180fa52ac85211b6
4
- data.tar.gz: 1ec2f8123d464dc6c4c51061e61867217175e721e136839762a678ebdf3a213c
3
+ metadata.gz: 31def49df321911a40f1bf5c30d7bb27fc55097ef64657232f8071f0f9bda0d5
4
+ data.tar.gz: 2b45c83b68ae3a6da95b5ac7337492024e52fbf4debb8ccb22bc14cc61ea287c
5
5
  SHA512:
6
- metadata.gz: fd4d22df63dc717615394a9f82533cf110d9551bf853ea22f11fd10f683f1e2efb9e0094a0324c7b57fa5016f8bb6eadaafa813bfa7eb0daebd162609a612416
7
- data.tar.gz: 0e590397f3ef47a2f18ddc43620ae781cff7e56aa7cdb67b444fbd834af613d49c1dbebe6d5aa0de24b96b84f84719594bfc1e0c55e0fd4d7e5dede9b1b3c783
6
+ metadata.gz: 387b95adfe0f8fa20a5bf87b9d35694cbdef925aac1f5288f20c65f2807790caca324917ec1337eea34e45986001e6b8b2d2669a551928f1c67ad95b62b965f9
7
+ data.tar.gz: e87e8ae29203dcbca596e9b11149923463ca7914ef5bc4fce3fd7b11f2101d5d22af63e580231340ce64906c52a1e9f1e2ee70b15238ca195d3053ad41a0c661
data/bin/cuco.bak ADDED
@@ -0,0 +1,20 @@
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 "cuco/version"
7
+ require "cuco/cuco"
8
+ require "cuco/controller"
9
+ require "micro-optparse"
10
+
11
+ options = Parser.new do |p|
12
+ p.banner = "Usage: cuco [options] [.watchr] # a file watcher"
13
+ p.version = "cuco #{Cuco::VERSION}"
14
+ p.option :debug, "Debugging output", default: false
15
+ end.process!
16
+
17
+ G.init(options, ARGV)
18
+
19
+ G.script = Script.new File.read(G.scriptname)
20
+ Controller.instance.run
@@ -17,7 +17,8 @@ class Controller
17
17
 
18
18
  @listener.start
19
19
  puts "*** Listen started" if debug
20
- sleep
20
+ # sleep # fails with Ruby 4.0.0
21
+ sleep 24 * 60 * 60
21
22
  end
22
23
 
23
24
  def stop
@@ -0,0 +1,66 @@
1
+ require "listen"
2
+ require "singleton"
3
+ require "cuco/cuco"
4
+ require "cuco/script"
5
+
6
+ class Controller
7
+ include Singleton
8
+
9
+ attr_reader :listener
10
+
11
+ def run
12
+ puts "*** Controller.run" if debug
13
+ @listener = Listen.to(".") do |modified, added, removed|
14
+ run_files(modified, :modified)
15
+ run_files(added, :added)
16
+ end
17
+
18
+ @listener.start
19
+ puts "*** Listen started" if debug
20
+ sleep
21
+ end
22
+
23
+ def stop
24
+ puts "*** Controller.stop" if debug
25
+ @listener&.stop
26
+ G.script = nil
27
+ @listener = nil
28
+ end
29
+
30
+ def run_files(files, type)
31
+ puts "*** Controller.run_files(#{files}, #{type})" if debug
32
+ if files.include?(G.scriptname)
33
+ G.script = Script.new File.read(G.scriptname)
34
+ return
35
+ end
36
+
37
+ files.map! { |filename| filename[G.pwd_length + 1..] }
38
+ files.each { |filename| file_run(filename, type) }
39
+ end
40
+
41
+ def file_run(pattern, type = nil)
42
+ puts "*** file_run(#{pattern}, #{type})" if debug
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
+ }
55
+ end
56
+
57
+ def match_run(rule, pattern)
58
+ md = pattern.match(rule.pattern)
59
+ puts "*** match_run #{rule}" if debug
60
+ rule.proc.call(md) if md
61
+ end
62
+
63
+ def debug
64
+ G.options[:debug]
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ class Script
2
+ attr_accessor :__rules
3
+
4
+ def initialize(str)
5
+ @__rules = []
6
+
7
+ instance_eval str
8
+ end
9
+
10
+ def watch(pattern, type = nil, &block)
11
+ @__rules << Rule.new(pattern, type, block)
12
+ end
13
+ end
14
+
15
+ # $ sudo sh -c "echo fs.inotify.max_user_watches=524288 >> /etc/sysctl.conf"
16
+ # $ sudo sysctl -p
data/lib/cuco/version.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Cuco
2
- VERSION = "0.1.4" # 2025-06-21
2
+ VERSION = "0.1.6" # 2025-12-28
3
+ # VERSION = "0.1.5" # 2025-12-28
4
+ # VERSION = "0.1.4" # 2025-06-21
3
5
  # VERSION = "0.1.3" # 2025-05-28
4
6
  # VERSION = "0.1.2" # 2024-05-21
5
7
  # VERSION = "0.1.1" # 2024-03-23
@@ -0,0 +1,13 @@
1
+ module Cuco
2
+ VERSION = "0.1.5" # 2025-12-28
3
+ # VERSION = "0.1.4" # 2025-06-21
4
+ # VERSION = "0.1.3" # 2025-05-28
5
+ # VERSION = "0.1.2" # 2024-05-21
6
+ # VERSION = "0.1.1" # 2024-03-23
7
+ # VERSION = "0.1.0" # 2024-03-18
8
+ # VERSION = "0.0.8" # 2024-03-18
9
+ # VERSION = "0.0.7" # 2024-03-18
10
+ # VERSION = "0.0.3" # 2024-03-12
11
+ # VERSION = "0.0.2" # 2024-03-11
12
+ # VERSION = "0.0.1" # 2024-03-05
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dittmar Krall
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: logger
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: micro-optparse
28
42
  requirement: !ruby/object:Gem::Requirement
@@ -77,10 +91,14 @@ files:
77
91
  - MIT-LICENSE
78
92
  - README.md
79
93
  - bin/cuco
94
+ - bin/cuco.bak
80
95
  - lib/cuco/controller.rb
96
+ - lib/cuco/controller.rb.bak
81
97
  - lib/cuco/cuco.rb
82
98
  - lib/cuco/script.rb
99
+ - lib/cuco/script.rb.bak
83
100
  - lib/cuco/version.rb
101
+ - lib/cuco/version.rb.bak
84
102
  homepage: http://www.matiq.de
85
103
  licenses:
86
104
  - MIT
@@ -90,7 +108,7 @@ require_paths:
90
108
  - lib
91
109
  required_ruby_version: !ruby/object:Gem::Requirement
92
110
  requirements:
93
- - - "~>"
111
+ - - ">="
94
112
  - !ruby/object:Gem::Version
95
113
  version: '3'
96
114
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -99,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
117
  - !ruby/object:Gem::Version
100
118
  version: '0'
101
119
  requirements: []
102
- rubygems_version: 3.6.7
120
+ rubygems_version: 4.0.3
103
121
  specification_version: 4
104
122
  summary: A file watcher
105
123
  test_files: []