build-files 0.2.1 → 0.2.2
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/build-files.gemspec +3 -1
- data/lib/build/files/directory.rb +24 -14
- data/lib/build/files/list.rb +2 -2
- data/lib/build/files/monitor.rb +4 -4
- data/lib/build/files/{filesystem.rb → path/filesystem.rb} +16 -1
- data/lib/build/files/path.rb +30 -15
- data/lib/build/files/version.rb +1 -1
- data/lib/build/files.rb +1 -1
- data/spec/build/files/directory_spec.rb +39 -0
- data/spec/build/files/path_spec.rb +18 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6e05a581a90d4c4b687188353883ff5b94bdbd2
|
4
|
+
data.tar.gz: 346cd2802c3cd5e343dcc27fffc2c3acde2012bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af419028f2a16b2caf1d59c261db593437efcb75bf5efd2952f0edc22f80e755d04ab130f9b59470ee124e42dee94d3f0208907ac414da35f095f72952f049a8
|
7
|
+
data.tar.gz: caf234a78d92532a3ef9a70e127bc33df3489434b5fca9e2dbfd2def28fa9c986cf436385613eb1503038bfa8ca140f55f2f5c6fbb06802afcab95bf823b7515
|
data/build-files.gemspec
CHANGED
@@ -17,7 +17,9 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
|
-
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rspec", "~> 3.0.0.rc1"
|
23
25
|
spec.add_development_dependency "rake"
|
@@ -23,45 +23,55 @@ require_relative 'list'
|
|
23
23
|
module Build
|
24
24
|
module Files
|
25
25
|
class Directory < List
|
26
|
-
def
|
27
|
-
|
26
|
+
def self.join(*args)
|
27
|
+
self.new(Path.join(*args))
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(path)
|
28
31
|
@path = path
|
29
32
|
end
|
30
33
|
|
31
|
-
attr :root
|
32
34
|
attr :path
|
33
35
|
|
34
|
-
def
|
35
|
-
|
36
|
+
def root
|
37
|
+
@path.root
|
36
38
|
end
|
37
39
|
|
38
|
-
def
|
39
|
-
|
40
|
+
def roots
|
41
|
+
[root]
|
40
42
|
end
|
41
|
-
|
43
|
+
|
42
44
|
def each
|
43
45
|
return to_enum(:each) unless block_given?
|
44
46
|
|
45
|
-
Dir.glob(
|
46
|
-
yield Path.new(path, @root)
|
47
|
+
Dir.glob(@path + "**/*") do |path|
|
48
|
+
yield Path.new(path, @path.root)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
50
52
|
def eql?(other)
|
51
|
-
other.kind_of?(self.class) and @
|
53
|
+
other.kind_of?(self.class) and @path.eql?(other.path)
|
52
54
|
end
|
53
55
|
|
54
56
|
def hash
|
55
|
-
|
57
|
+
@path.hash
|
56
58
|
end
|
57
59
|
|
58
60
|
def include?(path)
|
59
61
|
# Would be true if path is a descendant of full_path.
|
60
|
-
path.start_with?(
|
62
|
+
path.start_with?(@path)
|
61
63
|
end
|
62
64
|
|
63
65
|
def rebase(root)
|
64
|
-
self.class.new(
|
66
|
+
self.class.new(@path.rebase(root))
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_str
|
70
|
+
@path.to_str
|
71
|
+
end
|
72
|
+
|
73
|
+
def to_path
|
74
|
+
@path
|
65
75
|
end
|
66
76
|
end
|
67
77
|
end
|
data/lib/build/files/list.rb
CHANGED
data/lib/build/files/monitor.rb
CHANGED
@@ -80,6 +80,10 @@ module Build
|
|
80
80
|
|
81
81
|
handle
|
82
82
|
end
|
83
|
+
|
84
|
+
def run(options = {}, &block)
|
85
|
+
Files::run_with_polling(self, options, &block)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
def self.run_with_fsevent(monitor, options = {}, &block)
|
@@ -115,9 +119,5 @@ module Build
|
|
115
119
|
end
|
116
120
|
end
|
117
121
|
end
|
118
|
-
|
119
|
-
def run(monitor, options = {}, &block)
|
120
|
-
self.class.run_with_polling(monitor, options, &block)
|
121
|
-
end
|
122
122
|
end
|
123
123
|
end
|
@@ -20,8 +20,23 @@
|
|
20
20
|
|
21
21
|
module Build
|
22
22
|
module Files
|
23
|
-
# Represents a file path with an absolute root and a relative offset:
|
24
23
|
class Path
|
24
|
+
def open(mode, &block)
|
25
|
+
File.open(self, mode, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
def read(mode = File::RDONLY)
|
29
|
+
open(mode) do |file|
|
30
|
+
file.read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def write(buffer, mode = File::CREAT|File::TRUNC|File::WRONLY)
|
35
|
+
open(mode) do |file|
|
36
|
+
file.write(buffer)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
25
40
|
def exist?
|
26
41
|
File.exist? self
|
27
42
|
end
|
data/lib/build/files/path.rb
CHANGED
@@ -59,6 +59,10 @@ module Build
|
|
59
59
|
return full_path.slice(relative_offset..-1)
|
60
60
|
end
|
61
61
|
|
62
|
+
def self.[] path
|
63
|
+
self === path ? path : self.new(path.to_s)
|
64
|
+
end
|
65
|
+
|
62
66
|
# Both paths must be full absolute paths, and path must have root as an prefix.
|
63
67
|
def initialize(full_path, root = nil, relative_path = nil)
|
64
68
|
# This is the object identity:
|
@@ -73,11 +77,14 @@ module Build
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
|
-
|
77
80
|
def components
|
78
81
|
@components ||= @full_path.split(File::SEPARATOR)
|
79
82
|
end
|
80
83
|
|
84
|
+
def basename
|
85
|
+
self.components.last
|
86
|
+
end
|
87
|
+
|
81
88
|
# Ensure the path has an absolute root if it doesn't already:
|
82
89
|
def to_absolute(root)
|
83
90
|
if @root == "."
|
@@ -88,14 +95,7 @@ module Build
|
|
88
95
|
end
|
89
96
|
|
90
97
|
attr :root
|
91
|
-
|
92
|
-
def to_str
|
93
|
-
@full_path
|
94
|
-
end
|
95
|
-
|
96
|
-
def to_path
|
97
|
-
@full_path
|
98
|
-
end
|
98
|
+
attr :full_path
|
99
99
|
|
100
100
|
def length
|
101
101
|
@full_path.length
|
@@ -110,21 +110,28 @@ module Build
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def relative_parts
|
113
|
-
|
113
|
+
dirname, _, basename = self.relative_path.rpartition(File::SEPARATOR)
|
114
114
|
|
115
|
-
return
|
115
|
+
return dirname, basename
|
116
116
|
end
|
117
117
|
|
118
|
-
def
|
118
|
+
def append(extension)
|
119
119
|
self.class.new(@full_path + extension, @root)
|
120
120
|
end
|
121
121
|
|
122
|
+
def +(path)
|
123
|
+
self.class.new(File.join(@full_path, path), @root)
|
124
|
+
end
|
125
|
+
|
122
126
|
def rebase(root)
|
123
127
|
self.class.new(File.join(root, relative_path), root)
|
124
128
|
end
|
125
129
|
|
126
130
|
def with(root: @root, extension: nil)
|
127
|
-
self.
|
131
|
+
# self.relative_path should be a string so using + to add an extension should be fine.
|
132
|
+
relative_path = extension ? self.relative_path + extension : self.relative_path
|
133
|
+
|
134
|
+
self.class.new(File.join(root, relative_path), root, relative_path)
|
128
135
|
end
|
129
136
|
|
130
137
|
def self.join(root, relative_path)
|
@@ -135,6 +142,14 @@ module Build
|
|
135
142
|
self.class.shortest_path(self, root)
|
136
143
|
end
|
137
144
|
|
145
|
+
def to_str
|
146
|
+
@full_path
|
147
|
+
end
|
148
|
+
|
149
|
+
def to_path
|
150
|
+
@full_path
|
151
|
+
end
|
152
|
+
|
138
153
|
def to_s
|
139
154
|
@full_path
|
140
155
|
end
|
@@ -144,11 +159,11 @@ module Build
|
|
144
159
|
end
|
145
160
|
|
146
161
|
def hash
|
147
|
-
@full_path.hash
|
162
|
+
[@root, @full_path].hash
|
148
163
|
end
|
149
164
|
|
150
165
|
def eql?(other)
|
151
|
-
@full_path.eql?(other.
|
166
|
+
@root.eql?(other.root) and @full_path.eql?(other.full_path)
|
152
167
|
end
|
153
168
|
|
154
169
|
def ==(other)
|
data/lib/build/files/version.rb
CHANGED
data/lib/build/files.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
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 'build/files/directory'
|
22
|
+
|
23
|
+
module Build::Files::DirectorySpec
|
24
|
+
include Build::Files
|
25
|
+
|
26
|
+
describe Build::Files::Directory do
|
27
|
+
let(:path) {Path.new("/foo/bar/baz", "/bob")}
|
28
|
+
let(:directory) {Directory.new(path)}
|
29
|
+
|
30
|
+
it "has a root and path component" do
|
31
|
+
expect(directory.root).to be == path.root
|
32
|
+
expect(directory.path).to be == path
|
33
|
+
end
|
34
|
+
|
35
|
+
it "includes subpaths" do
|
36
|
+
expect(directory).to be_include "/foo/bar/baz/bob/dole"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -21,13 +21,24 @@
|
|
21
21
|
require 'build/files'
|
22
22
|
require 'build/files/path'
|
23
23
|
|
24
|
+
require 'pathname'
|
25
|
+
|
24
26
|
module Build::Files::PathSpec
|
25
27
|
include Build::Files
|
26
28
|
|
27
29
|
describe Build::Files::Path do
|
28
30
|
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
29
31
|
|
32
|
+
it "should convert to path" do
|
33
|
+
pathname = Pathname("/foo/bar/baz")
|
34
|
+
|
35
|
+
expect(Path[pathname]).to be == path
|
36
|
+
expect(Path["/foo/bar/baz"]).to be == path
|
37
|
+
end
|
38
|
+
|
30
39
|
it "should convert to string" do
|
40
|
+
expect(path.to_s).to be == "/foo/bar/baz"
|
41
|
+
|
31
42
|
# The to_str method should return the full path (i.e. the same as to_s):
|
32
43
|
expect(path.to_s).to be == path.to_str
|
33
44
|
|
@@ -60,7 +71,7 @@ module Build::Files::PathSpec
|
|
60
71
|
|
61
72
|
expect(renamed_path.relative_path).to be == 'bar/baz.txt'
|
62
73
|
|
63
|
-
object_path = path
|
74
|
+
object_path = path.append(".o")
|
64
75
|
|
65
76
|
expect(object_path.root).to be == "/foo"
|
66
77
|
expect(object_path.relative_path).to be == "bar/baz.o"
|
@@ -96,5 +107,11 @@ module Build::Files::PathSpec
|
|
96
107
|
|
97
108
|
expect(File.expand_path(short, output)).to be == input
|
98
109
|
end
|
110
|
+
|
111
|
+
it "should append a path" do
|
112
|
+
path = Path.new("/a/b/c")
|
113
|
+
|
114
|
+
expect(path + "d/e/f").to be == "/a/b/c/d/e/f"
|
115
|
+
end
|
99
116
|
end
|
100
117
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,13 +66,14 @@ files:
|
|
66
66
|
- build-files.gemspec
|
67
67
|
- lib/build/files.rb
|
68
68
|
- lib/build/files/directory.rb
|
69
|
-
- lib/build/files/filesystem.rb
|
70
69
|
- lib/build/files/glob.rb
|
71
70
|
- lib/build/files/list.rb
|
72
71
|
- lib/build/files/monitor.rb
|
73
72
|
- lib/build/files/path.rb
|
73
|
+
- lib/build/files/path/filesystem.rb
|
74
74
|
- lib/build/files/state.rb
|
75
75
|
- lib/build/files/version.rb
|
76
|
+
- spec/build/files/directory_spec.rb
|
76
77
|
- spec/build/files/list_spec.rb
|
77
78
|
- spec/build/files/path_spec.rb
|
78
79
|
- spec/build/files/state_spec.rb
|
@@ -88,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
89
|
requirements:
|
89
90
|
- - ">="
|
90
91
|
- !ruby/object:Gem::Version
|
91
|
-
version: '0'
|
92
|
+
version: '2.0'
|
92
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
94
|
requirements:
|
94
95
|
- - ">="
|
@@ -102,6 +103,7 @@ specification_version: 4
|
|
102
103
|
summary: Build::Files is a set of idiomatic classes for dealing with paths and monitoring
|
103
104
|
directories.
|
104
105
|
test_files:
|
106
|
+
- spec/build/files/directory_spec.rb
|
105
107
|
- spec/build/files/list_spec.rb
|
106
108
|
- spec/build/files/path_spec.rb
|
107
109
|
- spec/build/files/state_spec.rb
|