filewatcher 2.0.0.beta4 → 2.0.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/lib/filewatcher/snapshot.rb +32 -9
- data/{spec → lib/filewatcher}/spec_helper/ruby_watch_run.rb +6 -1
- data/lib/filewatcher/spec_helper/watch_run.rb +23 -24
- data/lib/filewatcher/spec_helper.rb +13 -7
- data/lib/filewatcher/version.rb +1 -1
- data/spec/filewatcher_spec.rb +40 -35
- data/spec/spec_helper.rb +0 -2
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59a457d937b483f6b936e5741df3ac777ef58fe43983c36de2fc00f9475e3e32
|
4
|
+
data.tar.gz: aca66c67a07d0d596afa06af04984a42f2d2fe83a6353bf84f11b34199e8379a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 384400d7f817cd4d403b977a9f7a52eca5b331a217829c013c42227d468e673f462b8072fae057ca60bf0048a9505994278aab0449f41620172ea97f443ef141
|
7
|
+
data.tar.gz: 17f903b43e2fd857d2b6b2f48bb81a51ebc175bb631089fda561ed082c29dda38e945ef9c6bbd21825310de9690f63021fc4c0bdce1aff132ce97d5323124871
|
data/lib/filewatcher/snapshot.rb
CHANGED
@@ -30,30 +30,53 @@ class Filewatcher
|
|
30
30
|
|
31
31
|
# Class for one file from snapshot
|
32
32
|
class SnapshotFile
|
33
|
-
|
33
|
+
class << self
|
34
|
+
def stats
|
35
|
+
@stats ||= populate_stats %i[mtime]
|
36
|
+
end
|
37
|
+
|
38
|
+
def populate_stats(stats)
|
39
|
+
defined?(super) ? super(stats) : stats
|
40
|
+
end
|
41
|
+
|
42
|
+
def subtractions
|
43
|
+
@subtractions ||= populate_subtractions(
|
44
|
+
created: ->(other) { other.nil? },
|
45
|
+
updated: ->(other) { mtime && mtime > other.mtime }
|
46
|
+
)
|
47
|
+
end
|
34
48
|
|
35
|
-
|
49
|
+
def populate_subtractions(hash)
|
50
|
+
hash = super(hash) if defined?(super)
|
51
|
+
hash
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
attr_reader :mtime
|
36
56
|
|
37
57
|
def initialize(filename)
|
38
58
|
@filename = filename
|
39
|
-
|
59
|
+
self.class.stats.each do |stat|
|
40
60
|
time = File.public_send(stat, filename) if File.exist?(filename)
|
41
61
|
instance_variable_set :"@#{stat}", time || Time.new(0)
|
42
62
|
end
|
43
63
|
end
|
44
64
|
|
45
65
|
def -(other)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
:updated
|
50
|
-
end
|
66
|
+
self.class.subtractions.find do |_event, block|
|
67
|
+
instance_exec(other, &block)
|
68
|
+
end&.first
|
51
69
|
end
|
52
70
|
|
53
71
|
def inspect
|
72
|
+
stats_string =
|
73
|
+
self.class.stats
|
74
|
+
.map { |stat| "#{stat}=#{public_send(stat)&.strftime('%F %T.%9N')&.inspect}" }
|
75
|
+
.join(', ')
|
76
|
+
|
54
77
|
<<~OUTPUT
|
55
78
|
#<Filewatcher::Snapshot::SnapshotFile:#{object_id}
|
56
|
-
@filename=#{@filename.inspect},
|
79
|
+
@filename=#{@filename.inspect}, #{stats_string}
|
57
80
|
>
|
58
81
|
OUTPUT
|
59
82
|
end
|
@@ -1,8 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'watch_run'
|
4
|
+
|
3
5
|
class Filewatcher
|
4
6
|
module SpecHelper
|
5
|
-
|
7
|
+
## Ruby API watcher for specs
|
8
|
+
class RubyWatchRun
|
9
|
+
include WatchRun
|
10
|
+
|
6
11
|
attr_reader :filewatcher, :thread, :watched, :processed
|
7
12
|
|
8
13
|
def initialize(filewatcher:, **args)
|
@@ -1,32 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'forwardable'
|
4
|
-
|
5
3
|
class Filewatcher
|
6
4
|
module SpecHelper
|
7
|
-
## Base
|
8
|
-
|
9
|
-
|
5
|
+
## Base module for Filewatcher runners in specs
|
6
|
+
module WatchRun
|
7
|
+
include Filewatcher::SpecHelper
|
10
8
|
|
11
9
|
TMP_DIR = "#{Dir.getwd}/spec/tmp"
|
12
10
|
|
13
|
-
def_delegators Filewatcher::SpecHelper, :debug, :wait, :system_stat
|
14
|
-
|
15
11
|
attr_reader :filename
|
16
12
|
|
17
|
-
def initialize(filename:, action
|
18
|
-
@filename =
|
19
|
-
if filename.match? %r{^(/|~|[A-Z]:)} then filename
|
20
|
-
else File.join(TMP_DIR, filename)
|
21
|
-
end
|
22
|
-
@directory = directory
|
13
|
+
def initialize(filename:, action:)
|
14
|
+
@filename = filename.match?(%r{^(/|~|[A-Z]:)}) ? filename : File.join(TMP_DIR, filename)
|
23
15
|
@action = action
|
24
16
|
debug "action = #{action}"
|
25
17
|
end
|
26
18
|
|
27
19
|
def start
|
28
20
|
debug 'start'
|
29
|
-
File.write(@filename, 'content1') unless @action
|
21
|
+
File.write(@filename, 'content1') unless %i[create create_dir].include? @action
|
30
22
|
|
31
23
|
wait seconds: 1
|
32
24
|
end
|
@@ -50,19 +42,26 @@ class Filewatcher
|
|
50
42
|
|
51
43
|
private
|
52
44
|
|
45
|
+
create_update_action = lambda do
|
46
|
+
## There is no `File.write` because of strange difference in parallel `File.mtime`
|
47
|
+
## https://cirrus-ci.com/task/6107605053472768?command=test#L497-L511
|
48
|
+
system "echo 'content2' > #{@filename}"
|
49
|
+
debug_file_mtime
|
50
|
+
end.freeze
|
51
|
+
|
52
|
+
ACTIONS = {
|
53
|
+
create: create_update_action,
|
54
|
+
update: create_update_action,
|
55
|
+
create_dir: -> { FileUtils.mkdir_p(@filename) },
|
56
|
+
delete: -> { FileUtils.remove(@filename) }
|
57
|
+
}.freeze
|
58
|
+
|
53
59
|
def make_changes
|
54
60
|
debug "make changes, @action = #{@action}, @filename = #{@filename}"
|
55
61
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
FileUtils.mkdir_p(@filename)
|
60
|
-
else
|
61
|
-
## There is no `File.write` because of strange difference in parallel `File.mtime`
|
62
|
-
## https://cirrus-ci.com/task/6107605053472768?command=test#L497-L511
|
63
|
-
system "echo 'content2' > #{@filename}"
|
64
|
-
debug_file_mtime
|
65
|
-
end
|
62
|
+
action = self.class::ACTIONS.fetch(@action) { raise "Unknown action `#{@action}`" }
|
63
|
+
|
64
|
+
instance_exec(&action)
|
66
65
|
|
67
66
|
wait seconds: 1
|
68
67
|
end
|
@@ -9,22 +9,23 @@ rescue LoadError
|
|
9
9
|
end
|
10
10
|
|
11
11
|
require_relative 'spec_helper/watch_run'
|
12
|
+
require_relative 'spec_helper/ruby_watch_run'
|
12
13
|
|
13
14
|
class Filewatcher
|
14
15
|
## Helper for common spec features between plugins
|
15
16
|
module SpecHelper
|
16
|
-
|
17
|
+
ENVIRONMENT_SPECS_COEFFICIENTS = {
|
18
|
+
-> { ENV.fetch('CI', false) } => 1,
|
19
|
+
-> { RUBY_PLATFORM == 'java' } => 1,
|
20
|
+
-> { Gem::Platform.local.os == 'darwin' } => 1
|
21
|
+
}.freeze
|
17
22
|
|
18
23
|
def logger
|
19
24
|
@logger ||= Logger.new($stdout, level: :debug)
|
20
25
|
end
|
21
26
|
|
22
27
|
def environment_specs_coefficients
|
23
|
-
|
24
|
-
-> { ENV['CI'] } => 1,
|
25
|
-
-> { RUBY_PLATFORM == 'java' } => 1,
|
26
|
-
-> { Gem::Platform.local.os == 'darwin' } => 1
|
27
|
-
}
|
28
|
+
ENVIRONMENT_SPECS_COEFFICIENTS
|
28
29
|
end
|
29
30
|
|
30
31
|
def wait(seconds: 1, interval: 1, &block)
|
@@ -62,7 +63,7 @@ class Filewatcher
|
|
62
63
|
|
63
64
|
def system_stat(filename)
|
64
65
|
case (host_os = RbConfig::CONFIG['host_os'])
|
65
|
-
when
|
66
|
+
when /linux(-gnu)?/
|
66
67
|
`stat --printf 'Modification: %y, Change: %z\n' #{filename}`
|
67
68
|
when /darwin\d*/
|
68
69
|
`stat #{filename}`
|
@@ -80,5 +81,10 @@ class Filewatcher
|
|
80
81
|
# debug command
|
81
82
|
`#{command}`
|
82
83
|
end
|
84
|
+
|
85
|
+
## https://github.com/rubocop/ruby-style-guide/issues/556#issuecomment-828672008
|
86
|
+
# rubocop:disable Style/ModuleFunction
|
87
|
+
extend self
|
88
|
+
# rubocop:enable Style/ModuleFunction
|
83
89
|
end
|
84
90
|
end
|
data/lib/filewatcher/version.rb
CHANGED
data/spec/filewatcher_spec.rb
CHANGED
@@ -28,7 +28,6 @@ describe Filewatcher do
|
|
28
28
|
|
29
29
|
let(:filename) { 'tmp_file.txt' }
|
30
30
|
let(:action) { :update }
|
31
|
-
let(:directory) { false }
|
32
31
|
## TODO: Check its needless
|
33
32
|
let(:every) { false }
|
34
33
|
let(:immediate) { false }
|
@@ -41,8 +40,7 @@ describe Filewatcher do
|
|
41
40
|
|
42
41
|
let(:watch_run) do
|
43
42
|
Filewatcher::SpecHelper::RubyWatchRun.new(
|
44
|
-
filename: filename, filewatcher: filewatcher, action: action
|
45
|
-
directory: directory
|
43
|
+
filename: filename, filewatcher: filewatcher, action: action
|
46
44
|
)
|
47
45
|
end
|
48
46
|
|
@@ -146,52 +144,59 @@ describe Filewatcher do
|
|
146
144
|
end
|
147
145
|
|
148
146
|
describe '#watch' do
|
149
|
-
|
150
|
-
|
147
|
+
context 'when action is known' do
|
148
|
+
before do
|
149
|
+
FileUtils.mkdir_p subdirectory if defined? subdirectory
|
151
150
|
|
152
|
-
|
153
|
-
|
151
|
+
watch_run.run
|
152
|
+
end
|
154
153
|
|
155
|
-
|
156
|
-
|
154
|
+
context 'when there are file deletions' do
|
155
|
+
let(:action) { :delete }
|
157
156
|
|
158
|
-
|
159
|
-
|
157
|
+
it { is_expected.to eq [{ watch_run.filename => :deleted }] }
|
158
|
+
end
|
160
159
|
|
161
|
-
|
162
|
-
|
160
|
+
context 'when there are file additions' do
|
161
|
+
let(:action) { :create }
|
163
162
|
|
164
|
-
|
165
|
-
|
163
|
+
it { is_expected.to eq [{ watch_run.filename => :created }] }
|
164
|
+
end
|
166
165
|
|
167
|
-
|
168
|
-
|
166
|
+
context 'when there are file updates' do
|
167
|
+
let(:action) { :update }
|
169
168
|
|
170
|
-
|
171
|
-
|
169
|
+
it { is_expected.to eq [{ watch_run.filename => :updated }] }
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when there are new files in subdirectories' do
|
173
|
+
let(:subdirectory) { File.expand_path('spec/tmp/new_sub_directory') }
|
172
174
|
|
173
|
-
|
174
|
-
|
175
|
+
let(:filename) { File.join(subdirectory, 'file.txt') }
|
176
|
+
let(:action) { :create }
|
177
|
+
let(:every) { true }
|
178
|
+
## https://github.com/filewatcher/filewatcher/pull/115#issuecomment-674581595
|
179
|
+
let(:interval) { 0.4 }
|
180
|
+
|
181
|
+
it do
|
182
|
+
expect(processed).to eq [
|
183
|
+
{ subdirectory => :updated, watch_run.filename => :created }
|
184
|
+
]
|
185
|
+
end
|
186
|
+
end
|
175
187
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
## https://github.com/filewatcher/filewatcher/pull/115#issuecomment-674581595
|
180
|
-
let(:interval) { 0.4 }
|
188
|
+
context 'when there are new subdirectories' do
|
189
|
+
let(:filename) { 'new_sub_directory' }
|
190
|
+
let(:action) { :create_dir }
|
181
191
|
|
182
|
-
|
183
|
-
expect(processed).to eq [
|
184
|
-
{ subdirectory => :updated, watch_run.filename => :created }
|
185
|
-
]
|
192
|
+
it { is_expected.to eq [{ watch_run.filename => :created }] }
|
186
193
|
end
|
187
194
|
end
|
188
195
|
|
189
|
-
context 'when
|
190
|
-
let(:
|
191
|
-
let(:directory) { true }
|
192
|
-
let(:action) { :create }
|
196
|
+
context 'when action is unknown' do
|
197
|
+
let(:action) { :foo }
|
193
198
|
|
194
|
-
|
199
|
+
specify { expect { watch_run.run }.to raise_error(RuntimeError, 'Unknown action `foo`') }
|
195
200
|
end
|
196
201
|
end
|
197
202
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -31,56 +31,56 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
34
|
+
version: 0.9.0
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
41
|
+
version: 0.9.0
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: gem_toys
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
48
|
+
version: 0.12.1
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
55
|
+
version: 0.12.1
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: toys
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 0.13.0
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.13.0
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: codecov
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 0.
|
76
|
+
version: 0.6.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: 0.
|
83
|
+
version: 0.6.0
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rspec
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,14 +101,14 @@ dependencies:
|
|
101
101
|
requirements:
|
102
102
|
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 1.36.0
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 1.36.0
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: rubocop-performance
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,17 +150,18 @@ files:
|
|
150
150
|
- lib/filewatcher/snapshot.rb
|
151
151
|
- lib/filewatcher/snapshots.rb
|
152
152
|
- lib/filewatcher/spec_helper.rb
|
153
|
+
- lib/filewatcher/spec_helper/ruby_watch_run.rb
|
153
154
|
- lib/filewatcher/spec_helper/watch_run.rb
|
154
155
|
- lib/filewatcher/version.rb
|
155
156
|
- spec/filewatcher/snapshot_spec.rb
|
156
157
|
- spec/filewatcher/version_spec.rb
|
157
158
|
- spec/filewatcher_spec.rb
|
158
159
|
- spec/spec_helper.rb
|
159
|
-
- spec/spec_helper/ruby_watch_run.rb
|
160
160
|
homepage: http://github.com/filewatcher/filewatcher
|
161
161
|
licenses:
|
162
162
|
- MIT
|
163
|
-
metadata:
|
163
|
+
metadata:
|
164
|
+
rubygems_mfa_required: 'true'
|
164
165
|
post_install_message:
|
165
166
|
rdoc_options: []
|
166
167
|
require_paths:
|
@@ -169,17 +170,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
170
|
requirements:
|
170
171
|
- - ">="
|
171
172
|
- !ruby/object:Gem::Version
|
172
|
-
version: '2.
|
173
|
+
version: '2.6'
|
173
174
|
- - "<"
|
174
175
|
- !ruby/object:Gem::Version
|
175
176
|
version: '4'
|
176
177
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
178
|
requirements:
|
178
|
-
- - "
|
179
|
+
- - ">="
|
179
180
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
181
|
+
version: '0'
|
181
182
|
requirements: []
|
182
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.3.7
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: Lightweight filewatcher.
|