build-files 0.3.4 → 1.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/build/files/directory.rb +2 -2
- data/lib/build/files/list.rb +11 -48
- data/lib/build/files/paths.rb +73 -0
- data/lib/build/files/{path/filesystem.rb → system.rb} +33 -5
- data/lib/build/files/version.rb +1 -1
- data/lib/build/files.rb +2 -1
- data/spec/build/files/directory_spec.rb +32 -1
- data/spec/build/files/glob_spec.rb +8 -0
- data/spec/build/files/list_spec.rb +8 -1
- data/spec/build/files/monitor_spec.rb +1 -1
- data/spec/build/files/state_spec.rb +27 -5
- data/spec/build/files/{filesystem_spec.rb → system_spec.rb} +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 175cf300ef1bb7f8873e0932c313a2d43ec1fdaf
|
4
|
+
data.tar.gz: 12f0e5f2dac80a6f59c7e1945fe6a04467604e39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19cbf2b9570233c4cd423f53e9c59e4053c6e3cf020157bcf1c2cae28389996872351cb374b9001ede12070de73b0a625d06ce5a0f56e8e8306e1c0576429b80
|
7
|
+
data.tar.gz: bac413fc3b5e4503d6ea4d85c8b2632134d8e603c0fdb84d5411f8b12412d84a3f2de673cca28b56c7427ca94723d1f93fbf097dc8a3b4df3d84965262294d25
|
data/lib/build/files/list.rb
CHANGED
@@ -35,6 +35,17 @@ module Build
|
|
35
35
|
Composite.new([self, list])
|
36
36
|
end
|
37
37
|
|
38
|
+
# This isn't very efficient, but it IS generic.
|
39
|
+
def ==(other)
|
40
|
+
if self.class == other.class
|
41
|
+
self.eql?(other)
|
42
|
+
elsif other.kind_of? self.class
|
43
|
+
self.to_a.sort == other.to_a.sort
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
38
49
|
# Does this list of files include the path of any other?
|
39
50
|
def intersects? other
|
40
51
|
other.any?{|path| include?(path)}
|
@@ -77,54 +88,6 @@ module Build
|
|
77
88
|
end
|
78
89
|
end
|
79
90
|
|
80
|
-
class Paths < List
|
81
|
-
def initialize(list, roots = nil)
|
82
|
-
@list = Array(list).freeze
|
83
|
-
@roots = roots
|
84
|
-
end
|
85
|
-
|
86
|
-
attr :list
|
87
|
-
|
88
|
-
# The list of roots for a given list of immutable files is also immutable, so we cache it for performance:
|
89
|
-
def roots
|
90
|
-
@roots ||= super
|
91
|
-
end
|
92
|
-
|
93
|
-
def count
|
94
|
-
@list.count
|
95
|
-
end
|
96
|
-
|
97
|
-
def each
|
98
|
-
return to_enum(:each) unless block_given?
|
99
|
-
|
100
|
-
@list.each{|path| yield path}
|
101
|
-
end
|
102
|
-
|
103
|
-
def eql?(other)
|
104
|
-
self.class.eql?(other.class) and @list.eql?(other.list)
|
105
|
-
end
|
106
|
-
|
107
|
-
def hash
|
108
|
-
@list.hash
|
109
|
-
end
|
110
|
-
|
111
|
-
def to_paths
|
112
|
-
self
|
113
|
-
end
|
114
|
-
|
115
|
-
def inspect
|
116
|
-
"<Paths #{@list.inspect}>"
|
117
|
-
end
|
118
|
-
|
119
|
-
def self.directory(root, relative_paths)
|
120
|
-
paths = relative_paths.collect do |path|
|
121
|
-
Path.join(root, path)
|
122
|
-
end
|
123
|
-
|
124
|
-
self.new(paths, [root])
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
91
|
class Composite < List
|
129
92
|
def initialize(files, roots = nil)
|
130
93
|
@files = []
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Copyright, 2014, 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_relative 'list'
|
22
|
+
|
23
|
+
module Build
|
24
|
+
module Files
|
25
|
+
class Paths < List
|
26
|
+
def initialize(list, roots = nil)
|
27
|
+
@list = Array(list).freeze
|
28
|
+
@roots = roots
|
29
|
+
end
|
30
|
+
|
31
|
+
attr :list
|
32
|
+
|
33
|
+
# The list of roots for a given list of immutable files is also immutable, so we cache it for performance:
|
34
|
+
def roots
|
35
|
+
@roots ||= super
|
36
|
+
end
|
37
|
+
|
38
|
+
def count
|
39
|
+
@list.count
|
40
|
+
end
|
41
|
+
|
42
|
+
def each
|
43
|
+
return to_enum(:each) unless block_given?
|
44
|
+
|
45
|
+
@list.each{|path| yield path}
|
46
|
+
end
|
47
|
+
|
48
|
+
def eql?(other)
|
49
|
+
self.class.eql?(other.class) and @list.eql?(other.list)
|
50
|
+
end
|
51
|
+
|
52
|
+
def hash
|
53
|
+
@list.hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_paths
|
57
|
+
self
|
58
|
+
end
|
59
|
+
|
60
|
+
def inspect
|
61
|
+
"<Paths #{@list.inspect}>"
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.directory(root, relative_paths)
|
65
|
+
paths = relative_paths.collect do |path|
|
66
|
+
Path.join(root, path)
|
67
|
+
end
|
68
|
+
|
69
|
+
self.new(paths, [root])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -20,54 +20,82 @@
|
|
20
20
|
|
21
21
|
require 'fileutils'
|
22
22
|
|
23
|
+
require_relative 'path'
|
24
|
+
require_relative 'list'
|
25
|
+
|
23
26
|
module Build
|
24
27
|
module Files
|
25
28
|
class Path
|
29
|
+
# Open a file with the specified mode.
|
26
30
|
def open(mode, &block)
|
27
31
|
File.open(self, mode, &block)
|
28
32
|
end
|
29
33
|
|
34
|
+
# Read the entire contents of the file.
|
30
35
|
def read(mode = File::RDONLY)
|
31
36
|
open(mode) do |file|
|
32
37
|
file.read
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
41
|
+
# Write a buffer to the file, creating it if it doesn't exist.
|
36
42
|
def write(buffer, mode = File::CREAT|File::TRUNC|File::WRONLY)
|
37
43
|
open(mode) do |file|
|
38
44
|
file.write(buffer)
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
48
|
+
# Touch the file, changing it's last modified time.
|
42
49
|
def touch
|
43
50
|
FileUtils.touch self
|
44
51
|
end
|
45
52
|
|
53
|
+
# Checks if the file exists in the local file system.
|
46
54
|
def exist?
|
47
55
|
File.exist? self
|
48
56
|
end
|
49
57
|
|
58
|
+
# Checks if the path refers to a directory.
|
50
59
|
def directory?
|
51
60
|
File.directory? self
|
52
61
|
end
|
53
62
|
|
63
|
+
# The time the file was last modified.
|
54
64
|
def modified_time
|
55
65
|
File.mtime self
|
56
66
|
end
|
57
67
|
|
58
|
-
|
59
|
-
|
68
|
+
# Recursively create a directory hierarchy for the given path.
|
60
69
|
def create
|
61
70
|
FileUtils.mkpath self
|
62
71
|
end
|
63
72
|
|
64
|
-
|
65
|
-
|
73
|
+
# Recursively delete the given path and all contents.
|
66
74
|
def delete
|
67
75
|
FileUtils.rm_rf self
|
68
76
|
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class List
|
80
|
+
# Touch all listed files.
|
81
|
+
def touch
|
82
|
+
each(&:touch)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Check that all files listed exist.
|
86
|
+
def exist?
|
87
|
+
all?(&:exist?)
|
88
|
+
end
|
69
89
|
|
70
|
-
|
90
|
+
# Recursively create paths for all listed paths.
|
91
|
+
def create
|
92
|
+
each(&:create)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Recursively delete all paths and all contents within those paths.
|
96
|
+
def delete
|
97
|
+
each(&:delete)
|
98
|
+
end
|
71
99
|
end
|
72
100
|
end
|
73
101
|
end
|
data/lib/build/files/version.rb
CHANGED
data/lib/build/files.rb
CHANGED
@@ -19,10 +19,11 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require_relative 'files/list'
|
22
|
+
require_relative 'files/paths'
|
22
23
|
require_relative 'files/glob'
|
23
24
|
require_relative 'files/directory'
|
24
25
|
|
25
26
|
require_relative 'files/state'
|
26
27
|
require_relative 'files/monitor'
|
27
28
|
|
28
|
-
require_relative 'files/
|
29
|
+
require_relative 'files/system'
|
@@ -24,16 +24,47 @@ module Build::Files::DirectorySpec
|
|
24
24
|
include Build::Files
|
25
25
|
|
26
26
|
describe Build::Files::Directory do
|
27
|
-
let(:path) {Path.new("/foo/bar/baz", "/
|
27
|
+
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
28
28
|
let(:directory) {Directory.new(path)}
|
29
29
|
|
30
|
+
it "can be constructed using join" do
|
31
|
+
joined_directory = Directory.join('/foo', 'bar/baz')
|
32
|
+
|
33
|
+
expect(joined_directory).to be == directory
|
34
|
+
end
|
35
|
+
|
30
36
|
it "has a root and path component" do
|
31
37
|
expect(directory.root).to be == path
|
38
|
+
expect(directory.to_path).to be == path
|
39
|
+
|
32
40
|
expect(directory.roots).to be_include(path)
|
33
41
|
end
|
34
42
|
|
43
|
+
it "can be converted into a string" do
|
44
|
+
expect(directory.to_str).to be == path.to_str
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can be used as a key" do
|
48
|
+
hash = {directory => true}
|
49
|
+
|
50
|
+
expect(hash).to be_include directory
|
51
|
+
end
|
52
|
+
|
35
53
|
it "includes subpaths" do
|
36
54
|
expect(directory).to be_include "/foo/bar/baz/bob/dole"
|
37
55
|
end
|
56
|
+
|
57
|
+
it "can be compared" do
|
58
|
+
other_directory = Directory.new(path + 'dole')
|
59
|
+
|
60
|
+
expect(directory).to be_eql directory
|
61
|
+
expect(directory).to_not be_eql other_directory
|
62
|
+
end
|
63
|
+
|
64
|
+
it "can be rebased" do
|
65
|
+
rebased_directory = directory.rebase("/fu")
|
66
|
+
|
67
|
+
expect(rebased_directory.root).to be == '/fu/bar/baz'
|
68
|
+
end
|
38
69
|
end
|
39
70
|
end
|
@@ -166,7 +166,14 @@ module Build::Files::ListSpec
|
|
166
166
|
|
167
167
|
cache[Paths.new(path)] = true
|
168
168
|
|
169
|
-
expect(cache).to
|
169
|
+
expect(cache).to be_include(Paths.new(path))
|
170
|
+
end
|
171
|
+
|
172
|
+
it "can be constructed from a list of relative paths" do
|
173
|
+
paths = Paths.directory('/foo', ['bar', 'baz', 'bob'])
|
174
|
+
|
175
|
+
expect(paths.count).to be 3
|
176
|
+
expect(paths).to be_include Path.new('/foo/bar')
|
170
177
|
end
|
171
178
|
end
|
172
179
|
end
|
@@ -56,13 +56,35 @@ module Build::Files::StateSpec
|
|
56
56
|
expect(state.removed).to be == []
|
57
57
|
expect(state.missing).to be == []
|
58
58
|
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe Build::Files::State do
|
62
|
+
before(:each) do
|
63
|
+
@temporary_files = Build::Files::Paths.directory(__dir__, ['a'])
|
64
|
+
@temporary_files.touch
|
65
|
+
|
66
|
+
@new_files = Build::Files::State.new(@temporary_files)
|
67
|
+
@old_files = Build::Files::State.new(Build::Files::Glob.new(__dir__, "*.rb"))
|
68
|
+
end
|
69
|
+
|
70
|
+
after(:each) do
|
71
|
+
@temporary_files.delete
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:empty) {Build::Files::State.new(Build::Files::Paths::NONE)}
|
59
75
|
|
60
76
|
it "should be clean with empty inputs or outputs" do
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
77
|
+
expect(Build::Files::State.dirty?(empty, @new_files)).to be false
|
78
|
+
expect(Build::Files::State.dirty?(@new_files, empty)).to be false
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be clean if files are newer" do
|
82
|
+
expect(Build::Files::State.dirty?(@old_files, @new_files)).to be false
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should be dirty if files are modified" do
|
86
|
+
# In this case, the file mtime is usually different so...
|
87
|
+
expect(Build::Files::State.dirty?(@new_files, @old_files)).to be true
|
66
88
|
end
|
67
89
|
end
|
68
90
|
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.
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2015-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,16 +71,17 @@ files:
|
|
71
71
|
- lib/build/files/list.rb
|
72
72
|
- lib/build/files/monitor.rb
|
73
73
|
- lib/build/files/path.rb
|
74
|
-
- lib/build/files/
|
74
|
+
- lib/build/files/paths.rb
|
75
75
|
- lib/build/files/state.rb
|
76
|
+
- lib/build/files/system.rb
|
76
77
|
- lib/build/files/version.rb
|
77
78
|
- spec/build/files/directory_spec.rb
|
78
|
-
- spec/build/files/filesystem_spec.rb
|
79
79
|
- spec/build/files/glob_spec.rb
|
80
80
|
- spec/build/files/list_spec.rb
|
81
81
|
- spec/build/files/monitor_spec.rb
|
82
82
|
- spec/build/files/path_spec.rb
|
83
83
|
- spec/build/files/state_spec.rb
|
84
|
+
- spec/build/files/system_spec.rb
|
84
85
|
homepage: ''
|
85
86
|
licenses:
|
86
87
|
- MIT
|
@@ -108,9 +109,9 @@ summary: Build::Files is a set of idiomatic classes for dealing with paths and m
|
|
108
109
|
directories.
|
109
110
|
test_files:
|
110
111
|
- spec/build/files/directory_spec.rb
|
111
|
-
- spec/build/files/filesystem_spec.rb
|
112
112
|
- spec/build/files/glob_spec.rb
|
113
113
|
- spec/build/files/list_spec.rb
|
114
114
|
- spec/build/files/monitor_spec.rb
|
115
115
|
- spec/build/files/path_spec.rb
|
116
116
|
- spec/build/files/state_spec.rb
|
117
|
+
- spec/build/files/system_spec.rb
|