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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abb6c94466f483db24dffb93c4d1189f03b4185f
4
- data.tar.gz: 990985cb06e27d114519e0e1a8d40f7959732e27
3
+ metadata.gz: 6df90ac78c9d807079619ae1314eae27e22a67e5
4
+ data.tar.gz: 16f3ec885b28ab92f6c0824e151eeed40068c71b
5
5
  SHA512:
6
- metadata.gz: 553935c6bd6a3ff6d1a345d8748f696660cbd406ab34ed49177f0daafa6e975724aee217dcca59eadde17d65126e03daf2b7f889921479003b5d1640302637d3
7
- data.tar.gz: 71ae0d548402827369e38368c7f13d298a0f6558ef4fe85e5304db22bb3c65514c2874897690db408ab6ab79293b76ea80cd603ad7c351d32b73ef3e1f3dfeee
6
+ metadata.gz: f40eabbf4d332f94fb182c784717feaf0ed4377e1db071493351a17a2580778bee42b1f99eb6c0f2fa3de8df3b028647ff8b655925ea54dcbfaa48543dd1be12
7
+ data.tar.gz: 235c60462c6bd7e0b1ed16e67be434f06efac87390082934b41afd773e1420122f0b33280a4cbd9108a64edf4f355e54a985ccce95faefb56a7108ebf6e6518e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changes
2
2
 
3
+ ## 0.3.2
4
+
5
+ * Fix infinite loop bug in #relative_from
6
+ * Fix handling of trailing slash in #cleanpath (and depended methods)
7
+
3
8
  ## 0.3.1
4
9
 
5
10
  * Fix missing require 'tmpdir' for using with mocked backend
@@ -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 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
@@ -2,7 +2,7 @@ class Path
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STAGE = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.').freeze
8
8
 
@@ -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.1
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-05-21 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler