rubypath 0.3.1 → 0.3.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/CHANGELOG.md +5 -0
- data/lib/rubypath/path_operations.rb +11 -5
- data/lib/rubypath/version.rb +1 -1
- data/spec/rubypath/path_operations_spec.rb +32 -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: 6df90ac78c9d807079619ae1314eae27e22a67e5
|
|
4
|
+
data.tar.gz: 16f3ec885b28ab92f6c0824e151eeed40068c71b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f40eabbf4d332f94fb182c784717feaf0ed4377e1db071493351a17a2580778bee42b1f99eb6c0f2fa3de8df3b028647ff8b655925ea54dcbfaa48543dd1be12
|
|
7
|
+
data.tar.gz: 235c60462c6bd7e0b1ed16e67be434f06efac87390082934b41afd773e1420122f0b33280a4cbd9108a64edf4f355e54a985ccce95faefb56a7108ebf6e6518e
|
data/CHANGELOG.md
CHANGED
|
@@ -82,8 +82,8 @@ class Path
|
|
|
82
82
|
#
|
|
83
83
|
# @return [Array<String>] File names.
|
|
84
84
|
#
|
|
85
|
-
def components
|
|
86
|
-
each_component.to_a
|
|
85
|
+
def components(*args)
|
|
86
|
+
each_component(*args).to_a
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
# Converts a pathname to an absolute pathname. Given arguments will be
|
|
@@ -268,13 +268,15 @@ class Path
|
|
|
268
268
|
def relative_from(base)
|
|
269
269
|
base, path = Path(base).cleanpath, cleanpath
|
|
270
270
|
|
|
271
|
+
return Path '.' if base == path
|
|
272
|
+
|
|
271
273
|
if (base.relative? && path.absolute?) || (base.absolute? && path.relative?)
|
|
272
274
|
raise ArgumentError.new \
|
|
273
275
|
"Different prefix: #{base.inspect} and #{path.inspect}"
|
|
274
276
|
end
|
|
275
277
|
|
|
276
|
-
base, path = base.components, path.components
|
|
277
|
-
base.shift && path.shift while base.first == path.first
|
|
278
|
+
base, path = base.components(empty: true), path.components(empty: true)
|
|
279
|
+
base.shift && path.shift while base.first == path.first && !(base.empty? || path.empty?)
|
|
278
280
|
|
|
279
281
|
Path(*((['..'] * base.size) + path))
|
|
280
282
|
end
|
|
@@ -299,7 +301,11 @@ class Path
|
|
|
299
301
|
if path == internal_path
|
|
300
302
|
self
|
|
301
303
|
else
|
|
302
|
-
Path
|
|
304
|
+
if internal_path[-1] == Path.separator
|
|
305
|
+
Path path, ''
|
|
306
|
+
else
|
|
307
|
+
Path path
|
|
308
|
+
end
|
|
303
309
|
end
|
|
304
310
|
end
|
|
305
311
|
end
|
data/lib/rubypath/version.rb
CHANGED
|
@@ -63,6 +63,11 @@ describe Path do
|
|
|
63
63
|
let(:path) { Path 'path/to/../../opath/to/./../file.txt' }
|
|
64
64
|
it { should eq 'opath/file.txt' }
|
|
65
65
|
end
|
|
66
|
+
|
|
67
|
+
context 'with trailing slash' do
|
|
68
|
+
let(:path) { Path 'path/to/../../dir/' }
|
|
69
|
+
it { expect(subject.to_s).to eq 'dir/' }
|
|
70
|
+
end
|
|
66
71
|
end
|
|
67
72
|
|
|
68
73
|
describe_method :each_component do
|
|
@@ -104,6 +109,13 @@ describe Path do
|
|
|
104
109
|
|
|
105
110
|
it { should be_a Array }
|
|
106
111
|
it { should eq %w(path to templates index.html) }
|
|
112
|
+
|
|
113
|
+
context 'with should include leading empty components' do
|
|
114
|
+
let(:str) { 'path/to/dir/' }
|
|
115
|
+
subject { path.send described_method, empty: true }
|
|
116
|
+
|
|
117
|
+
it { should eq ['path', 'to', 'dir', ''] }
|
|
118
|
+
end
|
|
107
119
|
end
|
|
108
120
|
|
|
109
121
|
describe_method :dirname, aliases: [:parent] do
|
|
@@ -331,6 +343,26 @@ describe Path do
|
|
|
331
343
|
let(:path) { Path '/path/one/two/six' }
|
|
332
344
|
it { should eq 'six' }
|
|
333
345
|
end
|
|
346
|
+
|
|
347
|
+
context 'with same path (I)' do
|
|
348
|
+
let(:base) { Path '/path/one/two/six' }
|
|
349
|
+
let(:path) { Path '/path/one/two/six' }
|
|
350
|
+
it { should eq '.' }
|
|
351
|
+
it { expect(subject.to_s).to eq '.' }
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
context 'with same path (I)' do
|
|
355
|
+
let(:base) { Path '/' }
|
|
356
|
+
let(:path) { Path '/' }
|
|
357
|
+
it { should eq '.' }
|
|
358
|
+
it { expect(subject.to_s).to eq '.' }
|
|
359
|
+
end
|
|
360
|
+
|
|
361
|
+
describe 'preserve trailing slash' do
|
|
362
|
+
let(:base) { Path('/blog/2014/06/my-blog-title-1/').dirname }
|
|
363
|
+
let(:path) { Path '/blog/2014/07/another-blog-title/' }
|
|
364
|
+
it { expect(subject.to_s).to eq '../07/another-blog-title/' }
|
|
365
|
+
end
|
|
334
366
|
end
|
|
335
367
|
|
|
336
368
|
describe_method :ascend, aliases: [:each_ancestors] do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubypath
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jan Graichen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-09-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|