build-files 0.3.3 → 0.3.4
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/build/files/monitor.rb +15 -3
- data/lib/build/files/path.rb +0 -9
- data/lib/build/files/version.rb +1 -1
- data/spec/build/files/filesystem_spec.rb +56 -0
- data/spec/build/files/list_spec.rb +44 -0
- data/spec/build/files/monitor_spec.rb +53 -31
- data/spec/build/files/path_spec.rb +26 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 219675f752dc63697b9075f9b14c5e528ad8571e
|
4
|
+
data.tar.gz: 632cd210ac7a90160607bb02ab03d70d33583a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88cfce577e99a4c3bba47890ce126675649e8880b8bc447d706a7c06bb45c663b3f5951824b2865cbe7f45d0040e29bd7b28a48a3925f08aeb582a05aa5ff5c1
|
7
|
+
data.tar.gz: 92471caf1ea8d0cd24713cacd34a92f04d5c02a37327489447cdc7b2fb5f7c267092e3fd9c565ea1dc88525c65fc73e7405ff9e1b2a44bb008c762a17c85f4ab
|
data/lib/build/files/monitor.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require 'set'
|
22
|
+
require 'logger'
|
22
23
|
|
23
24
|
require 'build/files/state'
|
24
25
|
|
@@ -51,23 +52,29 @@ module Build
|
|
51
52
|
end
|
52
53
|
|
53
54
|
class Monitor
|
54
|
-
def initialize
|
55
|
+
def initialize(logger: nil)
|
55
56
|
@directories = Hash.new { |hash, key| hash[key] = Set.new }
|
56
57
|
|
57
58
|
@updated = false
|
58
59
|
|
59
60
|
@deletions = nil
|
61
|
+
|
62
|
+
@logger = logger || Logger.new(nil)
|
60
63
|
end
|
61
64
|
|
62
65
|
attr :updated
|
63
66
|
|
64
67
|
# Notify the monitor that files in these directories have changed.
|
65
68
|
def update(directories, *args)
|
69
|
+
@logger.debug{"Update: #{directories} #{args.inspect}"}
|
70
|
+
|
66
71
|
delay_deletions do
|
67
72
|
directories.each do |directory|
|
68
|
-
#
|
73
|
+
@logger.debug{"Directory: #{directory}"}
|
69
74
|
|
70
75
|
@directories[directory].each do |handle|
|
76
|
+
@logger.debug{"Handle changed: #{handle.inspect}"}
|
77
|
+
|
71
78
|
handle.changed!(*args)
|
72
79
|
end
|
73
80
|
end
|
@@ -80,6 +87,7 @@ module Build
|
|
80
87
|
|
81
88
|
def delete(handle)
|
82
89
|
if @deletions
|
90
|
+
@logger.debug{"Delayed delete handle: #{handle}"}
|
83
91
|
@deletions << handle
|
84
92
|
else
|
85
93
|
purge(handle)
|
@@ -93,6 +101,8 @@ module Build
|
|
93
101
|
end
|
94
102
|
|
95
103
|
def add(handle)
|
104
|
+
@logger.debug{"Adding handle: #{handle}"}
|
105
|
+
|
96
106
|
handle.directories.each do |directory|
|
97
107
|
@directories[directory] << handle
|
98
108
|
|
@@ -113,7 +123,7 @@ module Build
|
|
113
123
|
else; :polling
|
114
124
|
end
|
115
125
|
|
116
|
-
if driver = options
|
126
|
+
if driver = (options[:driver] || default_driver)
|
117
127
|
method_name = "run_with_#{driver}"
|
118
128
|
Files.send(method_name, self, options, &block)
|
119
129
|
end
|
@@ -134,6 +144,8 @@ module Build
|
|
134
144
|
end
|
135
145
|
|
136
146
|
def purge(handle)
|
147
|
+
@logger.debug{"Purge handle: #{handle}"}
|
148
|
+
|
137
149
|
handle.directories.each do |directory|
|
138
150
|
@directories[directory].delete(handle)
|
139
151
|
|
data/lib/build/files/path.rb
CHANGED
@@ -88,15 +88,6 @@ module Build
|
|
88
88
|
self.components.last
|
89
89
|
end
|
90
90
|
|
91
|
-
# Ensure the path has an absolute root if it doesn't already:
|
92
|
-
def to_absolute(root)
|
93
|
-
if @root == "."
|
94
|
-
self.rebase(root)
|
95
|
-
else
|
96
|
-
self
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
91
|
attr :root
|
101
92
|
attr :full_path
|
102
93
|
|
data/lib/build/files/version.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'build/files'
|
22
|
+
require 'build/files/path'
|
23
|
+
require 'build/files/path/filesystem'
|
24
|
+
|
25
|
+
require 'pathname'
|
26
|
+
|
27
|
+
module Build::Files::FilesystemSpec
|
28
|
+
include Build::Files
|
29
|
+
|
30
|
+
describe Build::Files::Path do
|
31
|
+
let(:root) {Path.new(__dir__)}
|
32
|
+
let(:path) {root + "filesystem_spec"}
|
33
|
+
|
34
|
+
after(:each) do
|
35
|
+
path.delete
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should open file for writing" do
|
39
|
+
path.write("Hello World")
|
40
|
+
|
41
|
+
expect(File).to be_exist(path)
|
42
|
+
expect(path.read).to be == "Hello World"
|
43
|
+
|
44
|
+
expect(path).to be_exist
|
45
|
+
expect(path.directory?).to be == false
|
46
|
+
|
47
|
+
expect(path.modified_time.to_f).to be_within(5.0).of(Time.now.to_f)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should make a directory" do
|
51
|
+
path.create
|
52
|
+
|
53
|
+
expect(path.directory?).to be == true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -28,6 +28,50 @@ module Build::Files::ListSpec
|
|
28
28
|
describe Build::Files::Paths do
|
29
29
|
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
30
30
|
|
31
|
+
it "should be inspectable" do
|
32
|
+
paths = Paths.new(path)
|
33
|
+
|
34
|
+
expect(paths.inspect).to be_include path.inspect
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should be possible to convert to paths" do
|
38
|
+
paths = Paths.new(path)
|
39
|
+
|
40
|
+
expect(paths.to_paths).to be paths
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should be count number of paths" do
|
44
|
+
paths = Paths.new(path)
|
45
|
+
|
46
|
+
expect(paths.count).to be == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should coerce array to paths" do
|
50
|
+
paths = Paths.coerce([path])
|
51
|
+
|
52
|
+
expect(paths).to be_kind_of Paths
|
53
|
+
expect(paths.count).to be == 1
|
54
|
+
expect(paths).to be_include path
|
55
|
+
|
56
|
+
same_paths = Paths.coerce(paths)
|
57
|
+
expect(same_paths).to be paths
|
58
|
+
end
|
59
|
+
|
60
|
+
it "can add two lists of paths together" do
|
61
|
+
paths_a = Paths.new(path)
|
62
|
+
paths_b = Paths.new(Path.join('/foo/bar', 'alice'))
|
63
|
+
|
64
|
+
paths = paths_a + paths_b
|
65
|
+
|
66
|
+
expect(paths.count).to be 2
|
67
|
+
expect(paths).to be_include path
|
68
|
+
expect(paths).to be_kind_of Composite
|
69
|
+
|
70
|
+
# Composite equality
|
71
|
+
expect(paths).to be_eql paths
|
72
|
+
expect(paths).to_not be_eql paths_a
|
73
|
+
end
|
74
|
+
|
31
75
|
it "maps paths with a new extension" do
|
32
76
|
paths = Paths.new([
|
33
77
|
Path.join('/foo/bar', 'alice'),
|
@@ -31,48 +31,70 @@ module Build::Files::MonitorSpec
|
|
31
31
|
ROOT = File.expand_path('../tmp', __FILE__)
|
32
32
|
|
33
33
|
describe Build::Files::Monitor do
|
34
|
-
|
35
|
-
|
36
|
-
before(:all) do
|
37
|
-
Path.new(ROOT).mkpath
|
38
|
-
end
|
39
|
-
|
40
|
-
after(:all) do
|
41
|
-
Path.new(ROOT).rmpath
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should detect additions' do
|
45
|
-
directory = Build::Files::Directory.new(ROOT)
|
46
|
-
monitor = Build::Files::Monitor.new
|
47
|
-
|
48
|
-
changed = false
|
34
|
+
shared_examples_for Monitor do |driver|
|
35
|
+
let(:path) {Path.new(ROOT) + "test.txt"}
|
49
36
|
|
50
|
-
|
51
|
-
|
37
|
+
before(:all) do
|
38
|
+
Path.new(ROOT).create
|
52
39
|
end
|
53
40
|
|
54
|
-
|
41
|
+
after(:all) do
|
42
|
+
Path.new(ROOT).delete
|
43
|
+
end
|
55
44
|
|
56
|
-
|
57
|
-
|
45
|
+
it 'should detect additions' do
|
46
|
+
directory = Build::Files::Directory.new(ROOT)
|
47
|
+
monitor = Build::Files::Monitor.new
|
48
|
+
|
49
|
+
changed = false
|
50
|
+
|
51
|
+
monitor.track_changes(directory) do |state|
|
52
|
+
changed = state.added.include? path
|
53
|
+
end
|
54
|
+
|
55
|
+
touched = false
|
58
56
|
|
59
|
-
|
57
|
+
thread = Thread.new do
|
58
|
+
sleep 0.1
|
59
|
+
|
60
|
+
path.touch
|
61
|
+
|
62
|
+
touched = true
|
63
|
+
end
|
60
64
|
|
61
|
-
|
65
|
+
triggered = 0
|
66
|
+
|
67
|
+
monitor.run(driver: driver) do
|
68
|
+
triggered += 1
|
69
|
+
|
70
|
+
throw :interrupt if touched
|
71
|
+
end
|
72
|
+
|
73
|
+
thread.join
|
74
|
+
|
75
|
+
expect(changed).to be true
|
76
|
+
expect(triggered).to be >= 1
|
62
77
|
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Use the cross-platform driver, :polling
|
81
|
+
it_behaves_like Monitor, :polling
|
82
|
+
|
83
|
+
# Use the native platform driver, e.g. fsevent or inotify.
|
84
|
+
it_behaves_like Monitor
|
85
|
+
|
86
|
+
it "should add and remove monitored paths" do
|
87
|
+
directory = Build::Files::Directory.new(ROOT)
|
88
|
+
monitor = Build::Files::Monitor.new
|
63
89
|
|
64
|
-
|
65
|
-
|
66
|
-
monitor.run do
|
67
|
-
triggered += 1
|
68
|
-
|
69
|
-
throw :interrupt if touched
|
90
|
+
handler = monitor.track_changes(directory) do |state|
|
70
91
|
end
|
71
92
|
|
72
|
-
|
93
|
+
expect(monitor.roots).to be_include ROOT
|
94
|
+
|
95
|
+
handler.remove!
|
73
96
|
|
74
|
-
expect(
|
75
|
-
expect(triggered).to be >= 1
|
97
|
+
expect(monitor.roots).to be_empty
|
76
98
|
end
|
77
99
|
end
|
78
100
|
end
|
@@ -29,6 +29,11 @@ module Build::Files::PathSpec
|
|
29
29
|
describe Build::Files::Path do
|
30
30
|
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
31
31
|
|
32
|
+
it "should be inspectable" do
|
33
|
+
expect(path.inspect).to be_include path.root.to_s
|
34
|
+
expect(path.inspect).to be_include path.relative_path.to_s
|
35
|
+
end
|
36
|
+
|
32
37
|
it "should convert to path" do
|
33
38
|
pathname = Pathname("/foo/bar/baz")
|
34
39
|
|
@@ -123,11 +128,32 @@ module Build::Files::PathSpec
|
|
123
128
|
expect(path + "d/e/f").to be == "/a/b/c/d/e/f"
|
124
129
|
end
|
125
130
|
|
131
|
+
it "should give a list of components" do
|
132
|
+
expect(Path.components(path)).to be == ["", "foo", "bar", "baz"]
|
133
|
+
expect(Path.components(path.to_s)).to be == ["", "foo", "bar", "baz"]
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should give a basename" do
|
137
|
+
expect(path.basename).to be == "baz"
|
138
|
+
end
|
139
|
+
|
126
140
|
it "should have a new root" do
|
127
141
|
rerooted_path = path / "cat"
|
128
142
|
|
129
143
|
expect(rerooted_path.root).to be == "/foo/bar/baz"
|
130
144
|
expect(rerooted_path.relative_path).to be == "cat"
|
131
145
|
end
|
146
|
+
|
147
|
+
it "should give correct modes for reading" do
|
148
|
+
expect(path.for_reading).to be == [path.to_s, File::RDONLY]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should give correct modes for writing" do
|
152
|
+
expect(path.for_writing).to be == [path.to_s, File::CREAT|File::TRUNC|File::WRONLY]
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should give correct modes for appending" do
|
156
|
+
expect(path.for_appending).to be == [path.to_s, File::CREAT|File::APPEND|File::WRONLY]
|
157
|
+
end
|
132
158
|
end
|
133
159
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- lib/build/files/state.rb
|
76
76
|
- lib/build/files/version.rb
|
77
77
|
- spec/build/files/directory_spec.rb
|
78
|
+
- spec/build/files/filesystem_spec.rb
|
78
79
|
- spec/build/files/glob_spec.rb
|
79
80
|
- spec/build/files/list_spec.rb
|
80
81
|
- spec/build/files/monitor_spec.rb
|
@@ -107,6 +108,7 @@ summary: Build::Files is a set of idiomatic classes for dealing with paths and m
|
|
107
108
|
directories.
|
108
109
|
test_files:
|
109
110
|
- spec/build/files/directory_spec.rb
|
111
|
+
- spec/build/files/filesystem_spec.rb
|
110
112
|
- spec/build/files/glob_spec.rb
|
111
113
|
- spec/build/files/list_spec.rb
|
112
114
|
- spec/build/files/monitor_spec.rb
|