build-files 1.0.4 → 1.0.5
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/path.rb +23 -3
- data/lib/build/files/version.rb +1 -1
- data/spec/build/files/path_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9ede33f6827de41ac819213833225aee230195
|
4
|
+
data.tar.gz: 433c52df04cd60a80317f87a923089a246f9965e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d024fae752d2ec7a58748170f9c5f79c3af8edbd9d4b631360dcda2bc1b401a7fdf59c96a1f0813bdea7e34cd9508a8c092446926535857c227c219cf1af53a3
|
7
|
+
data.tar.gz: 4bc8f6ad273d381bc42efddd03cf1a4db18b6b4d170ba50d66e11d4c1e3c02ee76aaf806bdba86e01fcf5fe35b1155fc5f14361410fc0670fb270e08f278f650
|
data/lib/build/files/path.rb
CHANGED
@@ -22,6 +22,14 @@ module Build
|
|
22
22
|
module Files
|
23
23
|
# Represents a file path with an absolute root and a relative offset:
|
24
24
|
class Path
|
25
|
+
def self.split(path)
|
26
|
+
# Effectively dirname and basename:
|
27
|
+
dirname, separator, filename = path.rpartition(File::SEPARATOR)
|
28
|
+
filename, dot, extension = filename.rpartition('.')
|
29
|
+
|
30
|
+
return dirname + separator, filename, dot + extension
|
31
|
+
end
|
32
|
+
|
25
33
|
# Returns the length of the prefix which is shared by two strings.
|
26
34
|
def self.prefix_length(a, b)
|
27
35
|
[a.size, b.size].min.times{|i| return i if a[i] != b[i]}
|
@@ -128,9 +136,21 @@ module Build
|
|
128
136
|
self.class.new(File.join(root, relative_path), root)
|
129
137
|
end
|
130
138
|
|
131
|
-
def with(root: @root, extension: nil)
|
132
|
-
|
133
|
-
|
139
|
+
def with(root: @root, extension: nil, basename: false)
|
140
|
+
relative_path = self.relative_path
|
141
|
+
|
142
|
+
if basename
|
143
|
+
dirname, filename, _ = self.class.split(relative_path)
|
144
|
+
|
145
|
+
# Replace the filename if the basename is supplied:
|
146
|
+
filename = basename if basename.is_a? String
|
147
|
+
|
148
|
+
relative_path = dirname + filename
|
149
|
+
end
|
150
|
+
|
151
|
+
if extension
|
152
|
+
relative_path = relative_path + extension
|
153
|
+
end
|
134
154
|
|
135
155
|
self.class.new(File.join(root, relative_path), root, relative_path)
|
136
156
|
end
|
data/lib/build/files/version.rb
CHANGED
@@ -42,6 +42,20 @@ module Build::Files::PathSpec
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe Build::Files::Path.new("/foo/bar.txt") do
|
46
|
+
it "should replace existing file extension" do
|
47
|
+
expect(subject.with(extension: '.jpeg', basename: true)).to be == "/foo/bar.jpeg"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should append file extension" do
|
51
|
+
expect(subject.with(extension: '.jpeg')).to be == "/foo/bar.txt.jpeg"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should change basename" do
|
55
|
+
expect(subject.with(basename: 'baz', extension: '.txt')).to be == "/foo/baz.txt"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
describe Build::Files::Path.new("/foo/bar/baz", "/foo") do
|
46
60
|
it "should be inspectable" do
|
47
61
|
expect(subject.inspect).to be_include subject.root.to_s
|
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.5
|
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-04
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|