watchcat 0.0.1-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0e9991068cb31055ab4ca908d27c88d87324a1b389bcdd342db6229ef44b16d4
4
+ data.tar.gz: aa1109cf5f0eb047ee5a7f814d7455f4f8779056ee7923bf86e40a2832f1697d
5
+ SHA512:
6
+ metadata.gz: e440e90fc102a77a2f1f610d3b4511010e1b6aa6cdc9df7fdeabb5f593e79e46ea964bc084043738ae1aab0fd9ed4897b1a481835f815ba784b226242f71a6da
7
+ data.tar.gz: eb51a24287e1210e13c4e68ffc56770c0f7d3828e31f79fa5b1394576bd723afbcd2f08068c800716ab611a8b3525e4d4f8ca33d071bff44ee06e8373f01976c
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in watchcat.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ watchcat (0.0.1)
5
+ rb_sys
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ 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)
18
+ minitest (>= 5.0)
19
+ rake (13.0.6)
20
+ rake-compiler (1.2.1)
21
+ rake
22
+ rb_sys (0.9.65)
23
+ reline (0.3.2)
24
+ io-console (~> 0.5)
25
+
26
+ PLATFORMS
27
+ x86_64-darwin-19
28
+ x86_64-linux
29
+
30
+ DEPENDENCIES
31
+ debug
32
+ minitest
33
+ minitest-retry
34
+ rake
35
+ rake-compiler
36
+ watchcat!
37
+
38
+ BUNDLED WITH
39
+ 2.4.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Yuji Yaginuma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # Watchcat
2
+
3
+ Simple filesystem notification library for Ruby.
4
+
5
+ ## How
6
+
7
+ This gem uses [Notify](https://github.com/notify-rs/notify) to get notifications.
8
+
9
+ ## Platforms
10
+
11
+ This gem supports Linux and macOS. Due to the using `fork`, this doesn't support Windows now.
12
+
13
+ ## Installation
14
+
15
+ Install the gem and add to the application's Gemfile by executing:
16
+
17
+ $ bundle add watchcat
18
+
19
+ If bundler is not being used to manage dependencies, install the gem by executing:
20
+
21
+ $ gem install watchcat
22
+
23
+ ## Usage
24
+
25
+ Please specify a filename or directory and callback block to `Watchcat.watch`. The callback will call when the specified file or directory is changed.
26
+
27
+ ```ruby
28
+ require "watchcat"
29
+
30
+ w = Watchcat.watch("/tmp/test") do |e|
31
+ pp e.paths, e.kind
32
+ end
33
+
34
+ # Don't forget to call `stop`.
35
+ at_exit { w.stop }
36
+
37
+ sleep
38
+ ```
39
+
40
+ The value that is passed to the callback holds the paths that changed and the file change event. For example, if a file is created under the `/tmp/test`, you will get the following output.
41
+
42
+ ```
43
+ ["/tmp/test/a.txt"]
44
+ #<Watchcat::EventKind:0x00007f84be7161d8 @access=nil, @create=#<Watchcat::CreateKind:0x00007f84b99eaa08 @kind="file">, @modify=nil, @remove=nil>
45
+ ["/tmp/test/a.txt"]
46
+ #<Watchcat::EventKind:0x00007f84be7159b8
47
+ @access=nil,
48
+ @create=nil,
49
+ @modify=#<Watchcat::ModifyKind:0x00007f84be715968 @data_change=nil, @kind="metadata", @metadata=#<Watchcat::MetadataKind:0x00007f84b99e7a60 @kind=nil>, @rename=nil>,
50
+ @remove=nil>
51
+ ["/tmp/test/a.txt"]
52
+ #<Watchcat::EventKind:0x00007f84be714dd8
53
+ @access=#<Watchcat::AccessKind:0x00007f84b99e3708 @access_mode=#<Watchcat::AccessMode:0x00007f84b99e3640 @mode="write">, @kind="close">,
54
+ @create=nil,
55
+ @modify=nil,
56
+ @remove=nil>
57
+ ```
58
+
59
+ You can know what event is happened with `Watchcat::EventKind`. For example, what a file is changed or not, you can check with `Watchcat::EventKind#modify?`. Seed the following example for details.
60
+
61
+ ```ruby
62
+ require "watchcat"
63
+
64
+ w = Watchcat.watch("/tmp/target") do |e|
65
+ if e.kind.create?
66
+ if e.kind.create.file?
67
+ puts "'#{e.paths[0]}'(File) is added."
68
+ elsif e.kind.create.folder?
69
+ puts "'#{e.paths[0]}'(Folder) is added."
70
+ end
71
+ elsif e.kind.modify?
72
+ if e.kind.modify.data_change?
73
+ puts "'#{e.paths[0]}' is updated."
74
+ end
75
+ elsif e.kind.remove?
76
+ if e.kind.remove.file?
77
+ puts "'#{e.paths[0]}'(File) is removed."
78
+ elsif e.kind.remove.folder?
79
+ puts "'#{e.paths[0]}'(Folder) is removed."
80
+ end
81
+ end
82
+ end
83
+
84
+ # Don't forget to call `stop`.
85
+ at_exit { w.stop }
86
+
87
+ sleep
88
+ ```
89
+
90
+
91
+ **CAUTION** The `watchcat` doesn't normalize the events. So the result might change per the platform.
92
+
93
+
94
+ ### Options
95
+
96
+ | Name | Description | Default |
97
+ | -------------------------- | -----------------------------------------| ----------------- |
98
+ | **recursive** | Watch a directory recursively or not. | `true` |
99
+ | **force_polling** | Force to use a polling to watch. | `false` |
100
+
101
+
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/watchcat.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+ require "rb_sys/extensiontask"
5
+
6
+ task default: :test
7
+
8
+ GEMSPEC = Gem::Specification.load("watchcat.gemspec")
9
+ RbSys::ExtensionTask.new("watchcat", GEMSPEC) do |ext|
10
+ ext.lib_dir = "lib/watchcat"
11
+ end
12
+
13
+ Rake::TestTask.new do |t|
14
+ t.libs << "test"
15
+ t.libs << "lib"
16
+ t.deps << :compile
17
+ t.test_files = FileList[File.expand_path("test/**/*_test.rb", __dir__)]
18
+ t.warning = true
19
+ t.verbose = true
20
+ end
21
+
22
+ task console: :compile do
23
+ ruby "bin/console"
24
+ end
@@ -0,0 +1 @@
1
+ target
Binary file
Binary file
Binary file
@@ -0,0 +1,18 @@
1
+ module Watchcat
2
+ class Client
3
+ def initialize(uri, paths:, recursive:, force_polling:)
4
+ DRb.start_service
5
+ @watcher = Watchcat::Watcher.new
6
+ @server = DRbObject.new_with_uri(uri)
7
+ @paths = paths
8
+ @recursive = recursive
9
+ @force_polling = force_polling
10
+ end
11
+
12
+ def run
13
+ @watcher.watch(@paths, recursive: @recursive, force_polling: @force_polling) do |notification|
14
+ @server.execute(notification)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,50 @@
1
+ require "watchcat/kind"
2
+
3
+ module Watchcat
4
+ class Event
5
+ attr_reader :kind, :paths, :raw_kind
6
+
7
+ def initialize(kinds, paths, raw_kind)
8
+ @paths = paths
9
+ @raw_kind = raw_kind
10
+ build_kind(kinds)
11
+ end
12
+
13
+ private
14
+
15
+ def build_kind(kinds)
16
+ @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)
20
+ end
21
+
22
+ def build_access_kind(kinds)
23
+ @kind.access.kind = kinds.shift
24
+
25
+ if @kind.access.open? || @kind.access.close?
26
+ @kind.access.access_mode = Watchcat::AccessMode.new(kinds.shift)
27
+ end
28
+ end
29
+
30
+ def build_create_kind(kinds)
31
+ @kind.create.kind = kinds.shift
32
+ end
33
+
34
+ def build_modify_kind(kinds)
35
+ @kind.modify.kind = kinds.shift
36
+
37
+ if @kind.modify.data_change?
38
+ @kind.modify.data_change = Watchcat::DataChange.new(kinds.shift)
39
+ elsif @kind.modify.metadata?
40
+ @kind.modify.metadata = Watchcat::MetadataKind.new(kinds.shift)
41
+ elsif @kind.modify.rename?
42
+ @kind.modify.rename = Watchcat::RenameMode.new(kinds.shift)
43
+ end
44
+ end
45
+
46
+ def build_remove_kind(kinds)
47
+ @kind.remove.kind = kinds.shift
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,32 @@
1
+ require "drb"
2
+ require "drb/unix"
3
+ require_relative "server"
4
+ require_relative "client"
5
+
6
+ module Watchcat
7
+ class Executor
8
+ def initialize(paths, recursive:, force_polling:, block:)
9
+ @service = nil
10
+ @child_pid = nil
11
+ @paths = paths
12
+ @recursive = recursive
13
+ @force_polling = force_polling
14
+ @block = block
15
+ end
16
+
17
+ def start
18
+ server = Server.new(@block)
19
+ @service = DRb.start_service("drbunix:", server)
20
+ @child_pid = fork do
21
+ Process.setproctitle("watchcat: watcher")
22
+ client = Client.new(@service.uri, paths: @paths, recursive: @recursive, force_polling: @force_polling)
23
+ client.run
24
+ end
25
+ end
26
+
27
+ def stop
28
+ Process.kill(:KILL, @child_pid)
29
+ @service.stop_service
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,183 @@
1
+ require "forwardable"
2
+
3
+ module Watchcat
4
+ class EventKind
5
+ attr_accessor :access, :create, :modify, :remove
6
+
7
+ def initialize
8
+ @access, @create, @modify, @remove = nil, nil, nil, nil
9
+ end
10
+
11
+ def access?
12
+ !@access.nil?
13
+ end
14
+
15
+ def create?
16
+ !@create.nil?
17
+ end
18
+
19
+ def modify?
20
+ !@modify.nil?
21
+ end
22
+
23
+ def remove?
24
+ !@remove.nil?
25
+ end
26
+ end
27
+
28
+ class AccessKind
29
+ extend Forwardable
30
+
31
+ attr_accessor :kind, :access_mode
32
+ delegate [:excute_mode?, :read_mode?, :write_mode?] => :@access_mode
33
+
34
+ def initialize
35
+ @kind, @access_mode = nil, nil
36
+ end
37
+
38
+ def read?
39
+ @kind == "read"
40
+ end
41
+
42
+ def open?
43
+ @kind == "open"
44
+ end
45
+
46
+ def close?
47
+ @kind == "close"
48
+ end
49
+ end
50
+
51
+ class CreateKind
52
+ attr_accessor :kind
53
+
54
+ def file?
55
+ @kind == "file"
56
+ end
57
+
58
+ def folder?
59
+ @kind == "folder"
60
+ end
61
+ end
62
+
63
+ class ModifyKind
64
+ extend Forwardable
65
+
66
+ attr_accessor :kind, :data_change, :metadata, :rename
67
+ delegate [:size?, :content?] => :@data_change
68
+ delegate [:access_time?, :write_time?, :permission?, :ownership?, :extended?] => :@metadata
69
+ delegate [:from?, :to?, :both?] => :@rename
70
+
71
+ def initialize
72
+ @kind, @data_change, @metadata, @rename = nil, nil, nil, nil
73
+ end
74
+
75
+ def data_change?
76
+ @kind == "data_change"
77
+ end
78
+
79
+ def metadata?
80
+ @kind == "metadata"
81
+ end
82
+
83
+ def rename?
84
+ @kind == "rename"
85
+ end
86
+ end
87
+
88
+ class RemoveKind
89
+ attr_accessor :kind
90
+
91
+ def file?
92
+ @kind == "file"
93
+ end
94
+
95
+ def folder?
96
+ @kind == "folder"
97
+ end
98
+ end
99
+
100
+ class AccessMode
101
+ attr_accessor :mode
102
+
103
+ def initialize(mode)
104
+ @mode = mode
105
+ end
106
+
107
+ def execute_mode?
108
+ @mode == "execute"
109
+ end
110
+
111
+ def read_mode?
112
+ @mode == "read"
113
+ end
114
+
115
+ def write_mode?
116
+ @mode == "write"
117
+ end
118
+ end
119
+
120
+ class DataChange
121
+ attr_accessor :kind
122
+
123
+ def initialize(kind)
124
+ @kind = kind
125
+ end
126
+
127
+ def size?
128
+ @kind == "size"
129
+ end
130
+
131
+ def content?
132
+ @kind == "content"
133
+ end
134
+ end
135
+
136
+ class MetadataKind
137
+ attr_accessor :kind
138
+
139
+ def initialize(kind)
140
+ @kind = kind
141
+ end
142
+
143
+ def access_time?
144
+ @kind == "access_time"
145
+ end
146
+
147
+ def write_time?
148
+ @kind == "write_time"
149
+ end
150
+
151
+ def permission?
152
+ @kind == "permission"
153
+ end
154
+
155
+ def ownership?
156
+ @kind == "ownership"
157
+ end
158
+
159
+ def extended?
160
+ @kind == "extended"
161
+ end
162
+ end
163
+
164
+ class RenameMode
165
+ attr_accessor :mode
166
+
167
+ def initialize(mode)
168
+ @mode = mode
169
+ end
170
+
171
+ def from?
172
+ @mode == "from"
173
+ end
174
+
175
+ def to?
176
+ @mode == "to"
177
+ end
178
+
179
+ def both?
180
+ @mode == "both"
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,14 @@
1
+ require "watchcat/event"
2
+
3
+ module Watchcat
4
+ class Server
5
+ def initialize(block)
6
+ @block = block
7
+ end
8
+
9
+ def execute(notification)
10
+ event = Watchcat::Event.new(notification[0], notification[1], notification[2])
11
+ @block.call(event)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Watchcat
2
+ VERSION = "0.0.1"
3
+ end
data/lib/watchcat.rb ADDED
@@ -0,0 +1,18 @@
1
+ require_relative "watchcat/version"
2
+ require_relative "watchcat/executor"
3
+
4
+ begin
5
+ require "watchcat/#{RUBY_VERSION.to_f}/watchcat"
6
+ rescue LoadError
7
+ require "watchcat/watchcat"
8
+ end
9
+
10
+ module Watchcat
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)
14
+ w.start
15
+ w
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watchcat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: aarch64-linux
6
+ authors:
7
+ - Yuji Yaginuma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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-retry
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
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - yuuji.yaginuma@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - ext/watchcat/.gitignore
96
+ - lib/watchcat.rb
97
+ - lib/watchcat/3.0/watchcat.so
98
+ - lib/watchcat/3.1/watchcat.so
99
+ - lib/watchcat/3.2/watchcat.so
100
+ - lib/watchcat/client.rb
101
+ - lib/watchcat/event.rb
102
+ - lib/watchcat/executor.rb
103
+ - lib/watchcat/kind.rb
104
+ - lib/watchcat/server.rb
105
+ - lib/watchcat/version.rb
106
+ homepage: https://github.com/y-yagi/watchcat
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://github.com/y-yagi/watchcat
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '3.0'
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: 3.3.dev
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubygems_version: 3.4.4
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Simple filesystem notification library for Ruby.
133
+ test_files: []