watchcat 0.1.0-x86_64-linux → 0.2.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cccb1f972b3adfe188902976ea71173a6d4b044ac6e052048da0fbd2189434f1
4
- data.tar.gz: 0e0030524c299cb4a1a63489bcf50f379e7e22ce20c19e3f32a0aaa6d58d28e8
3
+ metadata.gz: 9a025a1b4cbebf5a6c767d8172de3d9e0e181f6eee4010d9b4a6dcf42c5d4d4e
4
+ data.tar.gz: 8441d5b0fb64a6e3ea62c3eec1e5b7acec7df240c99f2acb1bf9d23e3a8815c8
5
5
  SHA512:
6
- metadata.gz: 9cd6800c8b16c2ff7cfba83738bdc3cf4beff6b3f375d9bdc3c25387d545eb460b6507673965dc7b36f45dc1f54be81d69f519034a8f6858db24cad00d4be438
7
- data.tar.gz: 5b2a7297cdb0af6ef30c35ee8da64d347e797741428ecf35f5ab768d6c0ab401081e644731a0f73c7d8cf2783651ebf235a919592d87aca5084da526d7201834
6
+ metadata.gz: 9e35ad32453e91584fcf0f1acea9fe56f6d4eb001666bcb9823ef754756582e18b25f663f88f9c1237a9777120b62d31cef763c815f10614fa85557fefabffd3
7
+ data.tar.gz: '08f5d85dba38b5e3f87a6a27692b423e9b6e65f15effe46d09b4c102a1ff90a3f4261a0198c86d9347ffb8aacec3569553ca5afbaf9e36a3693a6998454540c3'
data/Gemfile.lock CHANGED
@@ -1,39 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- watchcat (0.1.0)
4
+ watchcat (0.2.0)
5
+ drb
5
6
  rb_sys
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- debug (1.7.1)
11
- irb (>= 1.5.0)
12
- reline (>= 0.3.1)
13
- io-console (0.6.0)
14
- irb (1.6.2)
15
- reline (>= 0.3.0)
16
- minitest (5.18.0)
17
- minitest-retry (0.2.2)
11
+ debug (1.9.2)
12
+ irb (~> 1.10)
13
+ reline (>= 0.3.8)
14
+ drb (2.2.1)
15
+ ffi (1.17.0-arm64-darwin)
16
+ ffi (1.17.0-x86_64-darwin)
17
+ ffi (1.17.0-x86_64-linux-gnu)
18
+ io-console (0.7.2)
19
+ irb (1.14.0)
20
+ rdoc (>= 4.0.0)
21
+ reline (>= 0.4.2)
22
+ listen (3.9.0)
23
+ rb-fsevent (~> 0.10, >= 0.10.3)
24
+ rb-inotify (~> 0.9, >= 0.9.10)
25
+ minitest (5.25.1)
26
+ minitest-retry (0.2.3)
18
27
  minitest (>= 5.0)
19
- rake (13.0.6)
20
- rake-compiler (1.2.1)
28
+ nokogiri (1.16.7-arm64-darwin)
29
+ racc (~> 1.4)
30
+ nokogiri (1.16.7-x86_64-darwin)
31
+ racc (~> 1.4)
32
+ nokogiri (1.16.7-x86_64-linux)
33
+ racc (~> 1.4)
34
+ psych (5.1.2)
35
+ stringio
36
+ racc (1.8.1)
37
+ rake (13.2.1)
38
+ rake-compiler (1.2.8)
21
39
  rake
22
- rb_sys (0.9.67)
23
- reline (0.3.2)
40
+ rb-fsevent (0.11.2)
41
+ rb-inotify (0.11.1)
42
+ ffi (~> 1.0)
43
+ rb_sys (0.9.102)
44
+ rdoc (6.7.0)
45
+ psych (>= 4.0.0)
46
+ reline (0.5.10)
24
47
  io-console (~> 0.5)
48
+ ruby_memcheck (3.0.0)
49
+ nokogiri
50
+ stringio (3.1.1)
25
51
 
26
52
  PLATFORMS
53
+ arm64-darwin-22
54
+ arm64-darwin-23
27
55
  x86_64-darwin-19
56
+ x86_64-darwin-20
28
57
  x86_64-linux
29
58
 
30
59
  DEPENDENCIES
31
60
  debug
61
+ listen
32
62
  minitest
33
63
  minitest-retry
34
64
  rake
35
65
  rake-compiler
66
+ ruby_memcheck
36
67
  watchcat!
37
68
 
38
69
  BUNDLED WITH
39
- 2.3.17
70
+ 2.5.4
data/README.md CHANGED
@@ -31,9 +31,6 @@ w = Watchcat.watch("/tmp/test") do |e|
31
31
  pp e.paths, e.kind
32
32
  end
33
33
 
34
- # Don't forget to call `stop`.
35
- at_exit { w.stop }
36
-
37
34
  sleep
38
35
  ```
39
36
 
@@ -81,9 +78,6 @@ w = Watchcat.watch("/tmp/target") do |e|
81
78
  end
82
79
  end
83
80
 
84
- # Don't forget to call `stop`.
85
- at_exit { w.stop }
86
-
87
81
  sleep
88
82
  ```
89
83
 
@@ -97,7 +91,7 @@ sleep
97
91
  | -------------------------- | -----------------------------------------| ----------------- |
98
92
  | **recursive** | Watch a directory recursively or not. | `true` |
99
93
  | **force_polling** | Force to use a polling to watch. | `false` |
100
-
94
+ | **debounce** | Debounce events for the same file. | `-1` |
101
95
 
102
96
 
103
97
  ## Contributing
data/Rakefile CHANGED
@@ -3,6 +3,8 @@
3
3
  require "rake/testtask"
4
4
  require "rb_sys/extensiontask"
5
5
  require "bundler/gem_tasks"
6
+ require "minitest/test_task"
7
+ require "ruby_memcheck"
6
8
 
7
9
  task default: :test
8
10
 
@@ -11,7 +13,7 @@ RbSys::ExtensionTask.new("watchcat", GEMSPEC) do |ext|
11
13
  ext.lib_dir = "lib/watchcat"
12
14
  end
13
15
 
14
- Rake::TestTask.new do |t|
16
+ test_config = lambda do |t|
15
17
  t.libs << "test"
16
18
  t.libs << "lib"
17
19
  t.deps << :compile
@@ -20,6 +22,24 @@ Rake::TestTask.new do |t|
20
22
  t.verbose = true
21
23
  end
22
24
 
25
+ Rake::TestTask.new(&test_config)
26
+ namespace :test do
27
+ RubyMemcheck::TestTask.new(:valgrind, &test_config)
28
+ end
29
+
30
+ Minitest::TestTask.create(:unit_test) do |t|
31
+ t.libs << "test"
32
+ t.libs << "lib"
33
+ t.warning = false
34
+ t.test_globs = ["test/**/*_test.rb"]
35
+ end
36
+
37
+ task :default => :test
38
+
23
39
  task console: :compile do
24
40
  ruby "bin/console"
25
41
  end
42
+
43
+ task example: :compile do
44
+ ruby "bin/example"
45
+ end
Binary file
Binary file
Binary file
Binary file
@@ -1,18 +1,26 @@
1
1
  module Watchcat
2
2
  class Client
3
- def initialize(uri, paths:, recursive:, force_polling:)
3
+ def initialize(uri, paths:, recursive:, force_polling:, poll_interval:, ignore_remove:, debounce:)
4
4
  DRb.start_service
5
5
  @watcher = Watchcat::Watcher.new
6
6
  @server = DRbObject.new_with_uri(uri)
7
7
  @paths = paths
8
8
  @recursive = recursive
9
9
  @force_polling = force_polling
10
+ @poll_interval = poll_interval
11
+ @ignore_remove = ignore_remove
12
+ @debounce = debounce
10
13
  end
11
14
 
12
15
  def run
13
- @watcher.watch(@paths, recursive: @recursive, force_polling: @force_polling) do |notification|
14
- @server.execute(notification)
15
- end
16
+ @watcher.watch(
17
+ @paths,
18
+ recursive: @recursive,
19
+ force_polling: @force_polling,
20
+ poll_interval: @poll_interval,
21
+ ignore_remove: @ignore_remove,
22
+ debounce: @debounce
23
+ ) { |notification| @server.execute(notification) }
16
24
  end
17
25
  end
18
26
  end
@@ -2,7 +2,7 @@ require "watchcat/kind"
2
2
 
3
3
  module Watchcat
4
4
  class Event
5
- attr_reader :kind, :paths, :raw_kind
5
+ attr_reader :kind, :paths, :raw_kind, :event
6
6
 
7
7
  def initialize(kinds, paths, raw_kind)
8
8
  @paths = paths
@@ -10,13 +10,26 @@ module Watchcat
10
10
  build_kind(kinds)
11
11
  end
12
12
 
13
+ def deconstruct_keys(_keys)
14
+ { paths: @paths, event: @event }
15
+ end
16
+
13
17
  private
14
18
 
15
19
  def build_kind(kinds)
16
20
  @kind = Watchcat::EventKind.new
17
- event_kind = kinds.shift
18
- @kind.public_send("#{event_kind}=", Object.const_get("Watchcat::#{event_kind.capitalize}Kind").new)
19
- send("build_#{event_kind}_kind", kinds)
21
+ @event = kinds.shift
22
+ if event
23
+ @kind.public_send("#{event}=", Object.const_get("Watchcat::#{event.capitalize}Kind").new)
24
+ send("build_#{event}_kind", kinds)
25
+ else
26
+ @kind.any = Watchcat::AnyKind.new
27
+ if File.directory?(@paths.first)
28
+ @kind.any.kind = "folder"
29
+ else
30
+ @kind.any.kind = "file"
31
+ end
32
+ end
20
33
  end
21
34
 
22
35
  def build_access_kind(kinds)
@@ -5,28 +5,60 @@ require_relative "client"
5
5
 
6
6
  module Watchcat
7
7
  class Executor
8
- def initialize(paths, recursive:, force_polling:, block:)
8
+ def initialize(paths, recursive:, force_polling:, poll_interval:, wait_until_startup:, ignore_remove:, debounce:, block:)
9
9
  @service = nil
10
10
  @child_pid = nil
11
11
  @paths = paths
12
12
  @recursive = recursive
13
13
  @force_polling = force_polling
14
+ @poll_interval = poll_interval
15
+ @wait_until_startup = wait_until_startup
16
+ @ignore_remove = ignore_remove
17
+ @debounce = debounce
14
18
  @block = block
15
19
  end
16
20
 
17
21
  def start
18
22
  server = Server.new(@block)
19
23
  @service = DRb.start_service("drbunix:", server)
24
+ client = nil
25
+ client = build_client if @wait_until_startup
26
+
20
27
  @child_pid = fork do
28
+ client = build_client unless @wait_until_startup
21
29
  Process.setproctitle("watchcat: watcher")
22
- client = Client.new(@service.uri, paths: @paths, recursive: @recursive, force_polling: @force_polling)
23
30
  client.run
24
31
  end
32
+
33
+ main = Process.pid
34
+ at_exit do
35
+ @exit_status = $!.status if $!.is_a?(SystemExit)
36
+ stop if Process.pid == main
37
+ exit @exit_status if @exit_status
38
+ end
25
39
  end
26
40
 
27
41
  def stop
28
- Process.kill(:KILL, @child_pid)
42
+ begin
43
+ Process.kill(:KILL, @child_pid)
44
+ rescue Errno::ESRCH
45
+ # NOTE: We can ignore this error because there process is already dead.
46
+ end
29
47
  @service.stop_service
30
48
  end
49
+
50
+ private
51
+
52
+ def build_client
53
+ Client.new(
54
+ @service.uri,
55
+ paths: @paths,
56
+ recursive: @recursive,
57
+ force_polling: @force_polling,
58
+ poll_interval: @poll_interval,
59
+ debounce: @debounce,
60
+ ignore_remove: @ignore_remove
61
+ )
62
+ end
31
63
  end
32
64
  end
data/lib/watchcat/kind.rb CHANGED
@@ -2,10 +2,10 @@ require "forwardable"
2
2
 
3
3
  module Watchcat
4
4
  class EventKind
5
- attr_accessor :access, :create, :modify, :remove
5
+ attr_accessor :access, :create, :modify, :remove, :any
6
6
 
7
7
  def initialize
8
- @access, @create, @modify, @remove = nil, nil, nil, nil
8
+ @access, @create, @modify, @remove, @any = nil, nil, nil, nil,nil
9
9
  end
10
10
 
11
11
  def access?
@@ -23,6 +23,10 @@ module Watchcat
23
23
  def remove?
24
24
  !@remove.nil?
25
25
  end
26
+
27
+ def any?
28
+ !@any.nil?
29
+ end
26
30
  end
27
31
 
28
32
  class AccessKind
@@ -97,6 +101,19 @@ module Watchcat
97
101
  end
98
102
  end
99
103
 
104
+ class AnyKind
105
+ attr_accessor :kind
106
+
107
+ def file?
108
+ @kind == "file"
109
+ end
110
+
111
+ def folder?
112
+ @kind == "folder"
113
+ end
114
+ end
115
+
116
+
100
117
  class AccessMode
101
118
  attr_accessor :mode
102
119
 
@@ -1,3 +1,3 @@
1
1
  module Watchcat
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/watchcat.rb CHANGED
@@ -9,8 +9,27 @@ end
9
9
 
10
10
  module Watchcat
11
11
  class << self
12
- def watch(paths, recursive: true, force_polling: false, &block)
13
- w = Watchcat::Executor.new(Array(paths), recursive: recursive, force_polling: force_polling, block: block)
12
+ def watch(
13
+ paths,
14
+ recursive: true,
15
+ force_polling: false,
16
+ poll_interval: nil,
17
+ wait_until_startup: false,
18
+ ignore_remove: false,
19
+ debounce: -1,
20
+ &block
21
+ )
22
+ w =
23
+ Watchcat::Executor.new(
24
+ Array(paths),
25
+ recursive: recursive,
26
+ force_polling: force_polling,
27
+ poll_interval: poll_interval,
28
+ wait_until_startup: wait_until_startup,
29
+ ignore_remove: ignore_remove,
30
+ debounce: debounce,
31
+ block: block
32
+ )
14
33
  w.start
15
34
  w
16
35
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watchcat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Yuji Yaginuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-13 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: drb
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: debug
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,34 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ruby_memcheck
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: listen
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
83
125
  description:
84
126
  email:
85
127
  - yuuji.yaginuma@gmail.com
@@ -97,6 +139,7 @@ files:
97
139
  - lib/watchcat/3.0/watchcat.so
98
140
  - lib/watchcat/3.1/watchcat.so
99
141
  - lib/watchcat/3.2/watchcat.so
142
+ - lib/watchcat/3.3/watchcat.so
100
143
  - lib/watchcat/client.rb
101
144
  - lib/watchcat/event.rb
102
145
  - lib/watchcat/executor.rb
@@ -108,6 +151,7 @@ licenses:
108
151
  - MIT
109
152
  metadata:
110
153
  homepage_uri: https://github.com/y-yagi/watchcat
154
+ rubygems_mfa_required: 'true'
111
155
  post_install_message:
112
156
  rdoc_options: []
113
157
  require_paths:
@@ -119,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
163
  version: '3.0'
120
164
  - - "<"
121
165
  - !ruby/object:Gem::Version
122
- version: 3.3.dev
166
+ version: 3.4.dev
123
167
  required_rubygems_version: !ruby/object:Gem::Requirement
124
168
  requirements:
125
169
  - - ">="