watchcat 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ watchcat (0.2.0)
5
+ drb
6
+ rb_sys
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
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)
27
+ minitest (>= 5.0)
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)
39
+ rake
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)
47
+ io-console (~> 0.5)
48
+ ruby_memcheck (3.0.0)
49
+ nokogiri
50
+ stringio (3.1.1)
51
+
52
+ PLATFORMS
53
+ arm64-darwin-22
54
+ arm64-darwin-23
55
+ x86_64-darwin-19
56
+ x86_64-darwin-20
57
+ x86_64-linux
58
+
59
+ DEPENDENCIES
60
+ debug
61
+ listen
62
+ minitest
63
+ minitest-retry
64
+ rake
65
+ rake-compiler
66
+ ruby_memcheck
67
+ watchcat!
68
+
69
+ BUNDLED WITH
70
+ 2.5.4
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,103 @@
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
+ sleep
35
+ ```
36
+
37
+ 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.
38
+
39
+ ```
40
+ ["/tmp/test/a.txt"]
41
+ #<Watchcat::EventKind:0x00007f84be7161d8 @access=nil, @create=#<Watchcat::CreateKind:0x00007f84b99eaa08 @kind="file">, @modify=nil, @remove=nil>
42
+ ["/tmp/test/a.txt"]
43
+ #<Watchcat::EventKind:0x00007f84be7159b8
44
+ @access=nil,
45
+ @create=nil,
46
+ @modify=#<Watchcat::ModifyKind:0x00007f84be715968 @data_change=nil, @kind="metadata", @metadata=#<Watchcat::MetadataKind:0x00007f84b99e7a60 @kind=nil>, @rename=nil>,
47
+ @remove=nil>
48
+ ["/tmp/test/a.txt"]
49
+ #<Watchcat::EventKind:0x00007f84be714dd8
50
+ @access=#<Watchcat::AccessKind:0x00007f84b99e3708 @access_mode=#<Watchcat::AccessMode:0x00007f84b99e3640 @mode="write">, @kind="close">,
51
+ @create=nil,
52
+ @modify=nil,
53
+ @remove=nil>
54
+ ```
55
+
56
+ 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.
57
+
58
+ ```ruby
59
+ require "watchcat"
60
+
61
+ w = Watchcat.watch("/tmp/target") do |e|
62
+ if e.kind.create?
63
+ if e.kind.create.file?
64
+ puts "'#{e.paths[0]}'(File) is added."
65
+ elsif e.kind.create.folder?
66
+ puts "'#{e.paths[0]}'(Folder) is added."
67
+ end
68
+ elsif e.kind.modify?
69
+ if e.kind.modify.data_change?
70
+ puts "'#{e.paths[0]}' is updated."
71
+ end
72
+ elsif e.kind.remove?
73
+ if e.kind.remove.file?
74
+ puts "'#{e.paths[0]}'(File) is removed."
75
+ elsif e.kind.remove.folder?
76
+ puts "'#{e.paths[0]}'(Folder) is removed."
77
+ end
78
+ end
79
+ end
80
+
81
+ sleep
82
+ ```
83
+
84
+
85
+ **CAUTION** The `watchcat` doesn't normalize the events. So the result might change per the platform.
86
+
87
+
88
+ ### Options
89
+
90
+ | Name | Description | Default |
91
+ | -------------------------- | -----------------------------------------| ----------------- |
92
+ | **recursive** | Watch a directory recursively or not. | `true` |
93
+ | **force_polling** | Force to use a polling to watch. | `false` |
94
+ | **debounce** | Debounce events for the same file. | `-1` |
95
+
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/y-yagi/watchcat.
100
+
101
+ ## License
102
+
103
+ 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,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake/testtask"
4
+ require "rb_sys/extensiontask"
5
+ require "bundler/gem_tasks"
6
+ require "minitest/test_task"
7
+ require "ruby_memcheck"
8
+
9
+ task default: :test
10
+
11
+ GEMSPEC = Gem::Specification.load("watchcat.gemspec")
12
+ RbSys::ExtensionTask.new("watchcat", GEMSPEC) do |ext|
13
+ ext.lib_dir = "lib/watchcat"
14
+ end
15
+
16
+ test_config = lambda do |t|
17
+ t.libs << "test"
18
+ t.libs << "lib"
19
+ t.deps << :compile
20
+ t.test_files = FileList[File.expand_path("test/**/*_test.rb", __dir__)]
21
+ t.warning = true
22
+ t.verbose = true
23
+ end
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
+
39
+ task console: :compile do
40
+ ruby "bin/console"
41
+ end
42
+
43
+ task example: :compile do
44
+ ruby "bin/example"
45
+ end
@@ -0,0 +1 @@
1
+ target