tidings 0.3.0 → 0.4.0
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 +4 -4
- data/README.md +43 -5
- data/ext/Makefile +19 -16
- data/ext/extconf.rb +6 -4
- data/ext/fs_event.bundle +0 -0
- data/ext/fs_event.o +0 -0
- data/lib/tidings.rb +9 -4
- data/lib/tidings/version.rb +4 -2
- data/lib/tidings/watcher.rb +13 -8
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ab6e749612d49a63cd3c2794d6c9fd66af4d96695c0487c77068cc9a7465f5
|
4
|
+
data.tar.gz: '09326f79c9abc7982d48a8cc24e2c8a3a54ddf22f23b9e54b2230afea55d47c5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884c3fe4f465b7c159ea25ea1f2341d7e1c847afb7c853cb90ae8c9ef50183d2df20e1f2aab03c59cc55321fa11492e2c26ab83a29cda4f9235dfeedc0f0694f
|
7
|
+
data.tar.gz: a152a046499ee07075503eddc1630341da08144066b9d8da50a2bfc68d90a1ee5e7dc1c65f536c487d726c5076b935e77f7a6c338da194388de08d914cc6fda7
|
data/README.md
CHANGED
@@ -4,13 +4,15 @@ A platform optimized file-change watcher.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
gem install tidings
|
8
8
|
|
9
|
-
##
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
Tidings registers with the operating system to receive callbacks for changes to the filesystem relative to a path. For every change it reports to anything that responds to: `call(file_or_path, flags)`. For example, a block:
|
10
12
|
|
11
13
|
```ruby
|
12
14
|
Tidings.watch('/Users/janice/Code') do |file_or_path, flags|
|
13
|
-
if flags.include(:dir)
|
15
|
+
if flags.include?(:dir)
|
14
16
|
puts "Change to directory: #{file_or_path}"
|
15
17
|
else
|
16
18
|
puts "Change to file: #{file_or_path}"
|
@@ -18,7 +20,7 @@ Tidings.watch('/Users/janice/Code') do |file_or_path, flags|
|
|
18
20
|
end
|
19
21
|
```
|
20
22
|
|
21
|
-
|
23
|
+
Or a class:
|
22
24
|
|
23
25
|
```ruby
|
24
26
|
module MyFileWatcher
|
@@ -28,4 +30,40 @@ module MyFileWatcher
|
|
28
30
|
end
|
29
31
|
|
30
32
|
Tidings.watch('/Users/janice/Code', MyFileWatcher)
|
31
|
-
|
33
|
+
```
|
34
|
+
|
35
|
+
Tidings swallows exceptions raised by the watcher because that's useful for ad-hoc scripts. If you don't want this you can either catch them yourself or drop down to Tidings internals.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Tidings.watch(__dir__) do |file|
|
39
|
+
do_something(file)
|
40
|
+
rescue Exception => e
|
41
|
+
$stderr.write("🤕 #{e.message}")
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
You can drop down to use the low-level implementation directly. Either `FSEvent` or `Inotify` will be defined depending on what compiled on your operating system.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'tidings'
|
49
|
+
|
50
|
+
def watch(path, &block)
|
51
|
+
if const_defined?(:FSEvent)
|
52
|
+
def watch
|
53
|
+
FSEvent.watch(path, block)
|
54
|
+
end
|
55
|
+
elsif const_defined?(:Inotify)
|
56
|
+
def watch
|
57
|
+
Inotify.watch(path, block)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
watch(__dir__) do |file|
|
63
|
+
puts "Change: #{file}"
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
## Copyright
|
68
|
+
|
69
|
+
MIT license, see COPYING.
|
data/ext/Makefile
CHANGED
@@ -12,12 +12,12 @@ NULLCMD = :
|
|
12
12
|
#### Start of system configuration section. ####
|
13
13
|
|
14
14
|
srcdir = fs_event
|
15
|
-
topdir = /Users/manfred/.rbenv/versions/2.
|
15
|
+
topdir = /Users/manfred/.rbenv/versions/2.7.2/include/ruby-2.7.0
|
16
16
|
hdrdir = $(topdir)
|
17
|
-
arch_hdrdir = /Users/manfred/.rbenv/versions/2.
|
17
|
+
arch_hdrdir = /Users/manfred/.rbenv/versions/2.7.2/include/ruby-2.7.0/x86_64-darwin20
|
18
18
|
PATH_SEPARATOR = :
|
19
19
|
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
|
20
|
-
prefix = $(DESTDIR)/Users/manfred/.rbenv/versions/2.
|
20
|
+
prefix = $(DESTDIR)/Users/manfred/.rbenv/versions/2.7.2
|
21
21
|
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
|
22
22
|
rubyarchprefix = $(rubylibprefix)/$(arch)
|
23
23
|
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
@@ -52,6 +52,7 @@ infodir = $(datarootdir)/info
|
|
52
52
|
docdir = $(datarootdir)/doc/$(PACKAGE)
|
53
53
|
oldincludedir = $(SDKROOT)/usr/include
|
54
54
|
includedir = $(prefix)/include
|
55
|
+
runstatedir = $(localstatedir)/run
|
55
56
|
localstatedir = $(prefix)/var
|
56
57
|
sharedstatedir = $(prefix)/com
|
57
58
|
sysconfdir = $(prefix)/etc
|
@@ -63,12 +64,13 @@ bindir = $(exec_prefix)/bin
|
|
63
64
|
archdir = $(rubyarchdir)
|
64
65
|
|
65
66
|
|
67
|
+
CC_WRAPPER =
|
66
68
|
CC = clang
|
67
69
|
CXX = clang++
|
68
|
-
LIBRUBY = $(
|
70
|
+
LIBRUBY = $(LIBRUBY_SO)
|
69
71
|
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
70
|
-
LIBRUBYARG_SHARED =
|
71
|
-
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework Foundation
|
72
|
+
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
73
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework Security -framework Foundation $(MAINLIBS)
|
72
74
|
empty =
|
73
75
|
OUTFLAG = -o $(empty)
|
74
76
|
COUTFLAG = -o $(empty)
|
@@ -76,18 +78,19 @@ CSRCFLAG = $(empty)
|
|
76
78
|
|
77
79
|
RUBY_EXTCONF_H =
|
78
80
|
cflags = $(optflags) $(debugflags) $(warnflags)
|
79
|
-
cxxflags =
|
81
|
+
cxxflags =
|
80
82
|
optflags = -O3
|
81
83
|
debugflags = -ggdb3
|
82
|
-
warnflags = -Wall -Wextra -
|
84
|
+
warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens
|
85
|
+
cppflags =
|
83
86
|
CCDLFLAGS = -fno-common
|
84
|
-
CFLAGS = $(CCDLFLAGS) -
|
87
|
+
CFLAGS = $(CCDLFLAGS) $(cflags) -fno-common -pipe $(ARCH_FLAG)
|
85
88
|
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
86
89
|
DEFS =
|
87
|
-
CPPFLAGS = -I/Users/manfred/.rbenv/versions/2.
|
88
|
-
CXXFLAGS = $(CCDLFLAGS)
|
90
|
+
CPPFLAGS = -I/Users/manfred/.rbenv/versions/2.7.2/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
|
91
|
+
CXXFLAGS = $(CCDLFLAGS) -g -O2 $(ARCH_FLAG)
|
89
92
|
ldflags = -framework CoreServices
|
90
|
-
dldflags = -L/Users/manfred/.rbenv/versions/2.
|
93
|
+
dldflags = -L/Users/manfred/.rbenv/versions/2.7.2/lib -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress
|
91
94
|
ARCH_FLAG =
|
92
95
|
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
93
96
|
LDSHARED = $(CC) -dynamic -bundle
|
@@ -96,15 +99,15 @@ AR = libtool -static
|
|
96
99
|
EXEEXT =
|
97
100
|
|
98
101
|
RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
|
99
|
-
RUBY_SO_NAME = ruby.2.
|
102
|
+
RUBY_SO_NAME = ruby.2.7
|
100
103
|
RUBYW_INSTALL_NAME =
|
101
104
|
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
|
102
105
|
RUBYW_BASE_NAME = rubyw
|
103
106
|
RUBY_BASE_NAME = ruby
|
104
107
|
|
105
|
-
arch = x86_64-
|
108
|
+
arch = x86_64-darwin20
|
106
109
|
sitearch = $(arch)
|
107
|
-
ruby_version = 2.
|
110
|
+
ruby_version = 2.7.0
|
108
111
|
ruby = $(bindir)/$(RUBY_BASE_NAME)
|
109
112
|
RUBY = $(ruby)
|
110
113
|
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h
|
@@ -134,7 +137,7 @@ extout =
|
|
134
137
|
extout_prefix =
|
135
138
|
target_prefix =
|
136
139
|
LOCAL_LIBS =
|
137
|
-
LIBS =
|
140
|
+
LIBS = $(LIBRUBYARG_SHARED)
|
138
141
|
ORIG_SRCS = fs_event.c
|
139
142
|
SRCS = $(ORIG_SRCS)
|
140
143
|
OBJS = fs_event.o
|
data/ext/extconf.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mkmf'
|
2
4
|
|
3
5
|
case RUBY_PLATFORM
|
4
6
|
when /darwin/
|
5
|
-
with_ldflags(
|
6
|
-
create_makefile(
|
7
|
+
with_ldflags('-framework CoreServices') do
|
8
|
+
create_makefile('fs_event', 'fs_event')
|
7
9
|
end
|
8
10
|
when /linux/
|
9
|
-
create_makefile(
|
10
|
-
end
|
11
|
+
create_makefile('inotify', 'inotify')
|
12
|
+
end
|
data/ext/fs_event.bundle
CHANGED
Binary file
|
data/ext/fs_event.o
CHANGED
Binary file
|
data/lib/tidings.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
case RUBY_PLATFORM
|
2
4
|
when /darwin/
|
3
5
|
require 'fs_event'
|
4
6
|
when /linux/
|
5
7
|
require 'inotify'
|
6
8
|
else
|
7
|
-
raise
|
9
|
+
raise "Your platform is currently not supported (#{RUBY_PLATFORM})"
|
8
10
|
end
|
9
11
|
|
12
|
+
# Contains the complete Tidings implementation.
|
13
|
+
#
|
14
|
+
# Tidings.watch(File.expand_path('~/Code`)) { |file| pp file }
|
10
15
|
module Tidings
|
11
16
|
autoload :VERSION, 'tidings/version'
|
12
17
|
autoload :Watcher, 'tidings/watcher'
|
13
18
|
|
14
19
|
def self.log(message)
|
15
|
-
|
20
|
+
warn("Tidings: #{message}") if $DEBUG
|
16
21
|
end
|
17
22
|
|
18
|
-
def self.watch(path, processor=nil, &block)
|
23
|
+
def self.watch(path, processor = nil, &block)
|
19
24
|
watcher = Tidings::Watcher.new(path, processor || block)
|
20
25
|
watcher.start
|
21
26
|
watcher
|
22
27
|
end
|
23
|
-
end
|
28
|
+
end
|
data/lib/tidings/version.rb
CHANGED
data/lib/tidings/watcher.rb
CHANGED
@@ -1,29 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Tidings
|
4
|
+
# Starts a file watcher in a separate process.
|
2
5
|
class Watcher
|
3
6
|
def initialize(path, processor)
|
4
|
-
@path
|
7
|
+
@path = path
|
8
|
+
@processor = processor
|
9
|
+
@pid = nil
|
5
10
|
end
|
6
11
|
|
7
12
|
def start
|
8
|
-
Signal.trap(
|
9
|
-
Signal.trap(
|
13
|
+
Signal.trap('HUP') { stop }
|
14
|
+
Signal.trap('SIGINT') { stop }
|
10
15
|
@pid = fork do
|
11
16
|
begin
|
12
17
|
watch
|
13
|
-
rescue Exception =>
|
18
|
+
rescue Exception => e
|
14
19
|
Tidings.log(
|
15
|
-
"Tidings encountered an uncaught exeption: #{
|
20
|
+
"Tidings encountered an uncaught exeption: #{e.message}"
|
16
21
|
)
|
17
22
|
exit
|
18
23
|
end
|
19
24
|
end
|
20
25
|
Tidings.log("Tidings running on PID: #{@pid}")
|
21
26
|
Process.waitpid(@pid)
|
22
|
-
Tidings.log(
|
27
|
+
Tidings.log('Tidings stopped running')
|
23
28
|
end
|
24
29
|
|
25
30
|
def stop
|
26
|
-
Process.kill(
|
31
|
+
Process.kill('KILL', @pid)
|
27
32
|
rescue Errno::ESRCH
|
28
33
|
end
|
29
34
|
|
@@ -37,4 +42,4 @@ module Tidings
|
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
40
|
-
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manfred Stienstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fakefs
|
@@ -63,8 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
|
67
|
-
rubygems_version: 2.7.6
|
66
|
+
rubygems_version: 3.1.4
|
68
67
|
signing_key:
|
69
68
|
specification_version: 4
|
70
69
|
summary: A platform optimized file-change watcher.
|