filewatch 0.6.7 → 0.6.8
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/filewatch/observing_tail.rb +100 -0
- data/lib/filewatch/tail.rb +13 -262
- data/lib/filewatch/tail_base.rb +220 -0
- data/lib/filewatch/watch.rb +121 -33
- data/lib/filewatch/yielding_tail.rb +79 -0
- metadata +17 -19
- data/spec/buftok_spec.rb +0 -18
- data/spec/tail_spec.rb +0 -232
- data/spec/watch_spec.rb +0 -120
- data/spec/winhelper_spec.rb +0 -22
data/spec/watch_spec.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
require 'filewatch/watch'
|
2
|
-
require 'stud/temporary'
|
3
|
-
|
4
|
-
describe FileWatch::Watch do
|
5
|
-
before(:all) do
|
6
|
-
@thread_abort = Thread.abort_on_exception
|
7
|
-
Thread.abort_on_exception = true
|
8
|
-
end
|
9
|
-
|
10
|
-
after(:all) do
|
11
|
-
Thread.abort_on_exception = @thread_abort
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:directory) { Stud::Temporary.directory }
|
15
|
-
let(:file_path) { File.join(directory, "1.log") }
|
16
|
-
let(:loggr) { double("loggr", :debug? => true) }
|
17
|
-
let(:results) { [] }
|
18
|
-
let(:quit_proc) do
|
19
|
-
lambda do
|
20
|
-
Thread.new do
|
21
|
-
sleep 1
|
22
|
-
subject.quit
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
let(:subscribe_proc) do
|
27
|
-
lambda do
|
28
|
-
subject.subscribe(0.1, 4) do |event, path|
|
29
|
-
results.push([event, path])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
let(:write_lines_1_and_2_proc) do
|
34
|
-
lambda do
|
35
|
-
File.open(file_path, "wb") { |file| file.write("line1\nline2\n") }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
subject { FileWatch::Watch.new(:logger => loggr) }
|
40
|
-
|
41
|
-
before do
|
42
|
-
allow(loggr).to receive(:debug)
|
43
|
-
end
|
44
|
-
|
45
|
-
after do
|
46
|
-
FileUtils.rm_rf(directory)
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when watching a directory with files" do
|
50
|
-
it "yields create_initial and one modify file events" do
|
51
|
-
write_lines_1_and_2_proc.call
|
52
|
-
subject.watch(File.join(directory, "*"))
|
53
|
-
quit_proc.call
|
54
|
-
subscribe_proc.call
|
55
|
-
expect(results).to eq([[:create_initial, file_path], [:modify, file_path]])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when watching a directory without files and one is added" do
|
60
|
-
it "yields create and one modify file events" do
|
61
|
-
subject.watch(File.join(directory, "*"))
|
62
|
-
write_lines_1_and_2_proc.call
|
63
|
-
|
64
|
-
quit_proc.call
|
65
|
-
subscribe_proc.call
|
66
|
-
|
67
|
-
expect(results).to eq([[:create, file_path], [:modify, file_path]])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when watching a directory with files and data is appended" do
|
72
|
-
let(:write_lines_3_and_4_proc) do
|
73
|
-
lambda do
|
74
|
-
Thread.new do
|
75
|
-
sleep 0.5
|
76
|
-
File.open(file_path, "ab") { |file| file.write("line3\nline4\n") }
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
it "yields create_initial and two modified file events" do
|
82
|
-
write_lines_1_and_2_proc.call
|
83
|
-
subject.watch(File.join(directory, "*"))
|
84
|
-
|
85
|
-
write_lines_3_and_4_proc.call # asynchronous
|
86
|
-
|
87
|
-
quit_proc.call
|
88
|
-
subscribe_proc.call
|
89
|
-
|
90
|
-
expect(results).to eq([[:create_initial, file_path], [:modify, file_path], [:modify, file_path]])
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
context "when unwatching a file and data is appended" do
|
95
|
-
let(:write_lines_3_and_4_proc) do
|
96
|
-
lambda do
|
97
|
-
Thread.new do
|
98
|
-
sleep 0.2
|
99
|
-
results.clear
|
100
|
-
subject.unwatch(file_path)
|
101
|
-
sleep 0.2
|
102
|
-
File.open(file_path, "ab") { |file| file.write("line3\nline4\n") }
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
it "does not yield events after unwatching" do
|
108
|
-
write_lines_1_and_2_proc.call
|
109
|
-
subject.watch(File.join(directory, "*"))
|
110
|
-
|
111
|
-
write_lines_3_and_4_proc.call # asynchronous
|
112
|
-
|
113
|
-
quit_proc.call
|
114
|
-
subscribe_proc.call
|
115
|
-
|
116
|
-
expect(results).to eq([])
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
data/spec/winhelper_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "stud/temporary"
|
2
|
-
require "fileutils"
|
3
|
-
|
4
|
-
if Gem.win_platform?
|
5
|
-
require "lib/filewatch/winhelper"
|
6
|
-
|
7
|
-
describe Winhelper do
|
8
|
-
let(:path) { Stud::Temporary.file.path }
|
9
|
-
|
10
|
-
after do
|
11
|
-
FileUtils.rm_rf(path)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "return a unique file identifier" do
|
15
|
-
volume_serial, file_index_low, file_index_high = Winhelper.GetWindowsUniqueFileIdentifier(path).split("").map(&:to_i)
|
16
|
-
|
17
|
-
expect(volume_serial).not_to eq(0)
|
18
|
-
expect(file_index_low).not_to eq(0)
|
19
|
-
expect(file_index_high).not_to eq(0)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|