build-files 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/build/files/path.rb +15 -2
- data/lib/build/files/version.rb +1 -1
- data/spec/build/files/path_spec.rb +45 -31
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a59583c2fd0e5a52a7049d0e709ae3e50cfeb4d
|
4
|
+
data.tar.gz: c59a6c774e10e2cf53765ee02dda6f79394792d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b8f1df86d30a44caa6c4192bc5443a660e2e9b98e81341690c675b0f6eab0ab75d26ae94ee90e5184b3c5fb6121b499a841973293c78dee54eca745be70890b
|
7
|
+
data.tar.gz: b06d12304725fd2327374cc27cc26dc1d390b2561400ef1fe049438dd35928d91a9c33a3e142410a56ecd689ecaa18dc1dfc26213a4b39e7d91a538640536b18
|
data/lib/build/files/path.rb
CHANGED
@@ -36,7 +36,7 @@ module Build
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
# Return the shortest relative path to get to path from root
|
39
|
+
# Return the shortest relative path to get to path from root. Root should be a directory with which you are computing the relative path.
|
40
40
|
def self.shortest_path(path, root)
|
41
41
|
path_components = Path.components(path)
|
42
42
|
root_components = Path.components(root)
|
@@ -95,10 +95,14 @@ module Build
|
|
95
95
|
self.parts.last
|
96
96
|
end
|
97
97
|
|
98
|
+
def start_with?(*args)
|
99
|
+
@full_path.start_with?(*args)
|
100
|
+
end
|
101
|
+
|
98
102
|
alias parts components
|
99
103
|
|
100
104
|
def relative_path
|
101
|
-
@relative_path ||= Path.relative_path(@root.to_s, @full_path)
|
105
|
+
@relative_path ||= Path.relative_path(@root.to_s, @full_path).freeze
|
102
106
|
end
|
103
107
|
|
104
108
|
def relative_parts
|
@@ -135,6 +139,15 @@ module Build
|
|
135
139
|
self.new(File.join(root, relative_path), root)
|
136
140
|
end
|
137
141
|
|
142
|
+
# Expand a subpath within a given root, similar to `File.expand_path`
|
143
|
+
def self.expand(subpath, root = Dir.getwd)
|
144
|
+
if subpath.start_with? File::SEPARATOR
|
145
|
+
self.new(subpath)
|
146
|
+
else
|
147
|
+
self.join(root, subpath)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
138
151
|
def shortest_path(root)
|
139
152
|
self.class.shortest_path(self, root)
|
140
153
|
end
|
data/lib/build/files/version.rb
CHANGED
@@ -27,65 +27,79 @@ module Build::Files::PathSpec
|
|
27
27
|
include Build::Files
|
28
28
|
|
29
29
|
describe Build::Files::Path do
|
30
|
-
|
30
|
+
it "should expand the path" do
|
31
|
+
expect(Build::Files::Path.expand("foo", "/bar")).to be == "/bar/foo"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Build::Files::Path.new("/test") do
|
36
|
+
it "should start_with? full path" do
|
37
|
+
expect(subject).to be_start_with '/test'
|
38
|
+
end
|
31
39
|
|
40
|
+
it "should start_with? partial pattern" do
|
41
|
+
expect(subject).to be_start_with '/te'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe Build::Files::Path.new("/foo/bar/baz", "/foo") do
|
32
46
|
it "should be inspectable" do
|
33
|
-
expect(
|
34
|
-
expect(
|
47
|
+
expect(subject.inspect).to be_include subject.root.to_s
|
48
|
+
expect(subject.inspect).to be_include subject.relative_path.to_s
|
35
49
|
end
|
36
50
|
|
37
51
|
it "should convert to path" do
|
38
52
|
pathname = Pathname("/foo/bar/baz")
|
39
53
|
|
40
|
-
expect(Path[pathname]).to be ==
|
41
|
-
expect(Path["/foo/bar/baz"]).to be ==
|
54
|
+
expect(Path[pathname]).to be == subject
|
55
|
+
expect(Path["/foo/bar/baz"]).to be == subject
|
42
56
|
end
|
43
57
|
|
44
58
|
it "should be equal" do
|
45
|
-
expect(
|
46
|
-
expect(
|
59
|
+
expect(subject).to be_eql subject
|
60
|
+
expect(subject).to be == subject
|
47
61
|
|
48
62
|
different_root_path = Path.join("/foo/bar", "baz")
|
49
|
-
expect(
|
50
|
-
expect(
|
63
|
+
expect(subject).to_not be_eql different_root_path
|
64
|
+
expect(subject).to be == different_root_path
|
51
65
|
end
|
52
66
|
|
53
67
|
it "should convert to string" do
|
54
|
-
expect(
|
68
|
+
expect(subject.to_s).to be == "/foo/bar/baz"
|
55
69
|
|
56
70
|
# The to_str method should return the full path (i.e. the same as to_s):
|
57
|
-
expect(
|
71
|
+
expect(subject.to_s).to be == subject.to_str
|
58
72
|
|
59
73
|
# Check the equality operator:
|
60
|
-
expect(
|
74
|
+
expect(subject).to be == subject.dup
|
61
75
|
|
62
76
|
# The length should be reported correctly:
|
63
|
-
expect(
|
77
|
+
expect(subject.length).to be == subject.to_s.length
|
64
78
|
|
65
79
|
# Check the return types:
|
66
|
-
expect(
|
67
|
-
expect(
|
68
|
-
expect(
|
80
|
+
expect(subject).to be_kind_of Path
|
81
|
+
expect(subject.root).to be_kind_of String
|
82
|
+
expect(subject.relative_path).to be_kind_of String
|
69
83
|
end
|
70
84
|
|
71
85
|
it "should consist of parts" do
|
72
|
-
expect(
|
86
|
+
expect(subject.parts).to be == ["", "foo", "bar", "baz"]
|
73
87
|
|
74
|
-
expect(
|
88
|
+
expect(subject.root).to be == "/foo"
|
75
89
|
|
76
|
-
expect(
|
90
|
+
expect(subject.relative_path).to be == "bar/baz"
|
77
91
|
|
78
|
-
expect(
|
92
|
+
expect(subject.relative_parts).to be == ["bar", "baz"]
|
79
93
|
end
|
80
94
|
|
81
95
|
it "should have a new extension" do
|
82
|
-
renamed_path =
|
96
|
+
renamed_path = subject.with(root: '/tmp', extension: '.txt')
|
83
97
|
|
84
98
|
expect(renamed_path.root).to be == '/tmp'
|
85
99
|
|
86
100
|
expect(renamed_path.relative_path).to be == 'bar/baz.txt'
|
87
101
|
|
88
|
-
object_path =
|
102
|
+
object_path = subject.append(".o")
|
89
103
|
|
90
104
|
expect(object_path.root).to be == "/foo"
|
91
105
|
expect(object_path.relative_path).to be == "bar/baz.o"
|
@@ -120,37 +134,37 @@ module Build::Files::PathSpec
|
|
120
134
|
end
|
121
135
|
|
122
136
|
it "should append a path" do
|
123
|
-
|
137
|
+
subject = Path.new("/a/b/c")
|
124
138
|
|
125
|
-
expect(
|
139
|
+
expect(subject + "d/e/f").to be == "/a/b/c/d/e/f"
|
126
140
|
end
|
127
141
|
|
128
142
|
it "should give a list of components" do
|
129
|
-
expect(Path.components(
|
130
|
-
expect(Path.components(
|
143
|
+
expect(Path.components(subject)).to be == ["", "foo", "bar", "baz"]
|
144
|
+
expect(Path.components(subject.to_s)).to be == ["", "foo", "bar", "baz"]
|
131
145
|
end
|
132
146
|
|
133
147
|
it "should give a basename" do
|
134
|
-
expect(
|
148
|
+
expect(subject.basename).to be == "baz"
|
135
149
|
end
|
136
150
|
|
137
151
|
it "should have a new root" do
|
138
|
-
rerooted_path =
|
152
|
+
rerooted_path = subject / "cat"
|
139
153
|
|
140
154
|
expect(rerooted_path.root).to be == "/foo/bar/baz"
|
141
155
|
expect(rerooted_path.relative_path).to be == "cat"
|
142
156
|
end
|
143
157
|
|
144
158
|
it "should give correct modes for reading" do
|
145
|
-
expect(
|
159
|
+
expect(subject.for_reading).to be == [subject.to_s, File::RDONLY]
|
146
160
|
end
|
147
161
|
|
148
162
|
it "should give correct modes for writing" do
|
149
|
-
expect(
|
163
|
+
expect(subject.for_writing).to be == [subject.to_s, File::CREAT|File::TRUNC|File::WRONLY]
|
150
164
|
end
|
151
165
|
|
152
166
|
it "should give correct modes for appending" do
|
153
|
-
expect(
|
167
|
+
expect(subject.for_appending).to be == [subject.to_s, File::CREAT|File::APPEND|File::WRONLY]
|
154
168
|
end
|
155
169
|
end
|
156
170
|
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: 1.0.
|
4
|
+
version: 1.0.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: 2016-
|
11
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
version: '0'
|
104
104
|
requirements: []
|
105
105
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
106
|
+
rubygems_version: 2.5.1
|
107
107
|
signing_key:
|
108
108
|
specification_version: 4
|
109
109
|
summary: Build::Files is a set of idiomatic classes for dealing with paths and monitoring
|