filewatcher 2.0.0.beta3 → 2.0.0.beta6
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/lib/filewatcher/snapshots.rb +0 -10
- data/{spec → lib/filewatcher}/spec_helper/ruby_watch_run.rb +6 -1
- data/lib/filewatcher/spec_helper/watch_run.rb +24 -25
- data/lib/filewatcher/spec_helper.rb +30 -6
- data/lib/filewatcher/version.rb +1 -1
- data/spec/filewatcher/snapshot_spec.rb +2 -1
- data/spec/filewatcher_spec.rb +41 -36
- data/spec/spec_helper.rb +0 -2
- metadata +29 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2db0cc5cc4a588900541eef784783e1548a596b29f7359108ff2f2fc9f6c6149
|
4
|
+
data.tar.gz: ac81956d8882c15525de3e3f4747b8e9b62631fa092e19441e925e16814a7a72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fdefea6d108c43026ee922706b8259bf6a7df32019a48c8bf88aa7cf06fb7dcf2942a7ca308c80d834201159af25d804948ca0d5b5b22155140ee0e15bc4305
|
7
|
+
data.tar.gz: 86bb17e7dd94046f4c357b80c264d9c4a9a720933ed1437e37e1a9547a4884ed0a5ae97f54ef6ca26cedfe76288212fa5053b1e8a5825cfdec6393981fbf155a
|
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
|
@@ -4,16 +4,6 @@ require_relative 'snapshot'
|
|
4
4
|
|
5
5
|
# Helpers in Filewatcher class itself
|
6
6
|
class Filewatcher
|
7
|
-
class << self
|
8
|
-
def system_stat(filename)
|
9
|
-
case Gem::Platform.local.os
|
10
|
-
when 'linux' then `stat --printf 'Modification: %y, Change: %z\n' #{filename}`
|
11
|
-
when 'darwin' then `stat #{filename}`
|
12
|
-
else 'Unknown OS for system `stat`'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
7
|
# Module for snapshot logic inside Filewatcher
|
18
8
|
module Snapshots
|
19
9
|
def found_filenames
|
@@ -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
|
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,25 +42,32 @@ 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
|
69
68
|
|
70
69
|
def debug_file_mtime
|
71
|
-
debug "stat #{@filename}: #{
|
70
|
+
debug "stat #{@filename}: #{system_stat(@filename)}"
|
72
71
|
debug "File.mtime = #{File.mtime(@filename).strftime('%F %T.%9N')}"
|
73
72
|
end
|
74
73
|
end
|
@@ -9,20 +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
|
17
|
+
ENVIRONMENT_SPECS_COEFFICIENTS = {
|
18
|
+
-> { ENV.fetch('CI', false) } => 1,
|
19
|
+
-> { RUBY_PLATFORM == 'java' } => 1,
|
20
|
+
-> { Gem::Platform.local.os == 'darwin' } => 1
|
21
|
+
}.freeze
|
22
|
+
|
16
23
|
def logger
|
17
24
|
@logger ||= Logger.new($stdout, level: :debug)
|
18
25
|
end
|
19
26
|
|
20
27
|
def environment_specs_coefficients
|
21
|
-
|
22
|
-
-> { ENV['CI'] } => 1,
|
23
|
-
-> { RUBY_PLATFORM == 'java' } => 3,
|
24
|
-
-> { Gem::Platform.local.os == 'darwin' } => 1
|
25
|
-
}
|
28
|
+
ENVIRONMENT_SPECS_COEFFICIENTS
|
26
29
|
end
|
27
30
|
|
28
31
|
def wait(seconds: 1, interval: 1, &block)
|
@@ -58,7 +61,28 @@ class Filewatcher
|
|
58
61
|
logger.debug "Thread ##{Thread.current.object_id} #{string}"
|
59
62
|
end
|
60
63
|
|
61
|
-
|
64
|
+
def system_stat(filename)
|
65
|
+
case (host_os = RbConfig::CONFIG['host_os'])
|
66
|
+
when /linux(-gnu)?/
|
67
|
+
`stat --printf 'Modification: %y, Change: %z\n' #{filename}`
|
68
|
+
when /darwin\d*/
|
69
|
+
`stat #{filename}`
|
70
|
+
when *Gem::WIN_PATTERNS
|
71
|
+
system_stat_windows filename
|
72
|
+
else
|
73
|
+
"Unknown OS `#{host_os}` for system's `stat` command"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def system_stat_windows(filename)
|
78
|
+
filename = filename.gsub('/', '\\\\\\')
|
79
|
+
properties = 'CreationDate,InstallDate,LastModified,LastAccessed'
|
80
|
+
command = "wmic datafile where Name=\"#{filename}\" get #{properties}"
|
81
|
+
# debug command
|
82
|
+
`#{command}`
|
83
|
+
end
|
84
|
+
|
85
|
+
## https://github.com/rubocop/ruby-style-guide/issues/556#issuecomment-828672008
|
62
86
|
# rubocop:disable Style/ModuleFunction
|
63
87
|
extend self
|
64
88
|
# rubocop:enable Style/ModuleFunction
|
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
|
|
@@ -51,7 +49,7 @@ describe Filewatcher do
|
|
51
49
|
describe '.print_version' do
|
52
50
|
subject(:method_call) { described_class.print_version }
|
53
51
|
|
54
|
-
let(:ruby_version_regexp) { 'j?ruby \d+\.\d+\.\d+.*' }
|
52
|
+
let(:ruby_version_regexp) { '(j|truffle)?ruby \d+\.\d+\.\d+.*' }
|
55
53
|
let(:filewatcher_version_regexp) { "Filewatcher #{Filewatcher::VERSION}" }
|
56
54
|
|
57
55
|
it do
|
@@ -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.beta6
|
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-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -25,48 +25,62 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '2.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler-audit
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.9.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.9.0
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: gem_toys
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
31
45
|
requirements:
|
32
46
|
- - "~>"
|
33
47
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
48
|
+
version: 0.12.1
|
35
49
|
type: :development
|
36
50
|
prerelease: false
|
37
51
|
version_requirements: !ruby/object:Gem::Requirement
|
38
52
|
requirements:
|
39
53
|
- - "~>"
|
40
54
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
55
|
+
version: 0.12.1
|
42
56
|
- !ruby/object:Gem::Dependency
|
43
57
|
name: toys
|
44
58
|
requirement: !ruby/object:Gem::Requirement
|
45
59
|
requirements:
|
46
60
|
- - "~>"
|
47
61
|
- !ruby/object:Gem::Version
|
48
|
-
version: 0.
|
62
|
+
version: 0.13.0
|
49
63
|
type: :development
|
50
64
|
prerelease: false
|
51
65
|
version_requirements: !ruby/object:Gem::Requirement
|
52
66
|
requirements:
|
53
67
|
- - "~>"
|
54
68
|
- !ruby/object:Gem::Version
|
55
|
-
version: 0.
|
69
|
+
version: 0.13.0
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: codecov
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
59
73
|
requirements:
|
60
74
|
- - "~>"
|
61
75
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
76
|
+
version: 0.6.0
|
63
77
|
type: :development
|
64
78
|
prerelease: false
|
65
79
|
version_requirements: !ruby/object:Gem::Requirement
|
66
80
|
requirements:
|
67
81
|
- - "~>"
|
68
82
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
83
|
+
version: 0.6.0
|
70
84
|
- !ruby/object:Gem::Dependency
|
71
85
|
name: rspec
|
72
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +101,14 @@ dependencies:
|
|
87
101
|
requirements:
|
88
102
|
- - "~>"
|
89
103
|
- !ruby/object:Gem::Version
|
90
|
-
version:
|
104
|
+
version: 1.32.0
|
91
105
|
type: :development
|
92
106
|
prerelease: false
|
93
107
|
version_requirements: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
109
|
- - "~>"
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
111
|
+
version: 1.32.0
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: rubocop-performance
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,17 +150,18 @@ files:
|
|
136
150
|
- lib/filewatcher/snapshot.rb
|
137
151
|
- lib/filewatcher/snapshots.rb
|
138
152
|
- lib/filewatcher/spec_helper.rb
|
153
|
+
- lib/filewatcher/spec_helper/ruby_watch_run.rb
|
139
154
|
- lib/filewatcher/spec_helper/watch_run.rb
|
140
155
|
- lib/filewatcher/version.rb
|
141
156
|
- spec/filewatcher/snapshot_spec.rb
|
142
157
|
- spec/filewatcher/version_spec.rb
|
143
158
|
- spec/filewatcher_spec.rb
|
144
159
|
- spec/spec_helper.rb
|
145
|
-
- spec/spec_helper/ruby_watch_run.rb
|
146
160
|
homepage: http://github.com/filewatcher/filewatcher
|
147
161
|
licenses:
|
148
162
|
- MIT
|
149
|
-
metadata:
|
163
|
+
metadata:
|
164
|
+
rubygems_mfa_required: 'true'
|
150
165
|
post_install_message:
|
151
166
|
rdoc_options: []
|
152
167
|
require_paths:
|
@@ -155,7 +170,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
170
|
requirements:
|
156
171
|
- - ">="
|
157
172
|
- !ruby/object:Gem::Version
|
158
|
-
version: '2.
|
173
|
+
version: '2.6'
|
159
174
|
- - "<"
|
160
175
|
- !ruby/object:Gem::Version
|
161
176
|
version: '4'
|
@@ -165,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
180
|
- !ruby/object:Gem::Version
|
166
181
|
version: 1.3.1
|
167
182
|
requirements: []
|
168
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.3.7
|
169
184
|
signing_key:
|
170
185
|
specification_version: 4
|
171
186
|
summary: Lightweight filewatcher.
|