filepath 0.6 → 0.7

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.
@@ -1,7 +1,7 @@
1
1
  # This is free software released into the public domain (CC0 license).
2
2
 
3
3
 
4
- class FilePathList
4
+ class FilepathList
5
5
  include Enumerable
6
6
 
7
7
  SEPARATOR = ':'.freeze
@@ -13,7 +13,7 @@ class FilePathList
13
13
 
14
14
  def select_entries(type)
15
15
  raw_entries = @entries.delete_if { |e| !e.send(type.to_s + '?') }
16
- return FilePathList.new(raw_entries)
16
+ return FilepathList.new(raw_entries)
17
17
  end
18
18
 
19
19
  def files
@@ -33,26 +33,26 @@ class FilePathList
33
33
  end
34
34
 
35
35
  def +(extra_entries)
36
- return FilePathList.new(@entries + extra_entries.to_a)
36
+ return FilepathList.new(@entries + extra_entries.to_a)
37
37
  end
38
38
 
39
39
  def -(others)
40
40
  remaining_entries = @entries - others.as_path_list.to_a
41
41
 
42
- return FilePathList.new(remaining_entries)
42
+ return FilepathList.new(remaining_entries)
43
43
  end
44
44
 
45
45
  def <<(extra_path)
46
- return FilePathList.new(@entries + [extra_path.as_path])
46
+ return FilepathList.new(@entries + [extra_path.as_path])
47
47
  end
48
48
 
49
49
  def *(other_list)
50
- if !other_list.is_a? FilePathList
51
- other_list = FilePathList.new(Array(other_list))
50
+ if !other_list.is_a? FilepathList
51
+ other_list = FilepathList.new(Array(other_list))
52
52
  end
53
53
  other_entries = other_list.entries
54
54
  paths = @entries.product(other_entries).map { |p1, p2| p1 / p2 }
55
- return FilePathList.new(paths)
55
+ return FilepathList.new(paths)
56
56
  end
57
57
 
58
58
  def remove_common_segments
@@ -75,10 +75,10 @@ class FilePathList
75
75
 
76
76
  remaining_segs = all_segs.map { |segs| segs[idx_different..-1] }
77
77
 
78
- return FilePathList.new(remaining_segs)
78
+ return FilepathList.new(remaining_segs)
79
79
  end
80
80
 
81
- # @return [FilePathList] the path list itself
81
+ # @return [FilepathList] the path list itself
82
82
 
83
83
  def as_path_list
84
84
  self
@@ -130,7 +130,7 @@ class FilePathList
130
130
  module EntriesMethods
131
131
  def map(&block)
132
132
  mapped_entries = @entries.map(&block)
133
- return FilePathList.new(mapped_entries)
133
+ return FilepathList.new(mapped_entries)
134
134
  end
135
135
 
136
136
  def select(pattern = nil, &block)
@@ -140,7 +140,7 @@ class FilePathList
140
140
 
141
141
  remaining_entries = @entries.select { |e| block.call(e) }
142
142
 
143
- return FilePathList.new(remaining_entries)
143
+ return FilepathList.new(remaining_entries)
144
144
  end
145
145
 
146
146
  def exclude(pattern = nil, &block)
@@ -2,18 +2,18 @@
2
2
 
3
3
  require File.join(File.dirname(__FILE__), 'spec_helper')
4
4
 
5
- describe FilePath do
5
+ describe Filepath do
6
6
  before(:all) do
7
- @root = FilePath.new(FIXTURES_DIR)
7
+ @root = Filepath.new(FIXTURES_DIR)
8
8
  end
9
9
 
10
10
  it "can be created from a string" do
11
- FilePath.new("foo").should be_a FilePath
11
+ Filepath.new("foo").should be_a Filepath
12
12
  end
13
13
 
14
- it "can be created from another FilePath" do
15
- orig = FilePath.new("foo")
16
- FilePath.new(orig).should be_a FilePath
14
+ it "can be created from another Filepath" do
15
+ orig = Filepath.new("foo")
16
+ Filepath.new(orig).should be_a Filepath
17
17
  end
18
18
 
19
19
  describe "#/" do
@@ -26,23 +26,23 @@ describe FilePath do
26
26
  ]
27
27
  test_data.each do |base, extra, result|
28
28
  it "concatenates `#{base}` and `#{extra}` (as String) into `#{result}`" do
29
- ph = FilePath.new(base) / extra
29
+ ph = Filepath.new(base) / extra
30
30
  ph.should == result
31
31
  end
32
32
  end
33
33
 
34
34
  test_data.each do |base, extra, result|
35
- it "concatenates `#{base}` and `#{extra}` (as FilePath) into `#{result}`" do
36
- ph = FilePath.new(base) / FilePath.new(extra)
35
+ it "concatenates `#{base}` and `#{extra}` (as Filepath) into `#{result}`" do
36
+ ph = Filepath.new(base) / Filepath.new(extra)
37
37
  ph.should == result
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
42
  describe "#+" do
43
- it "is deprecated but performs as FilePath#/" do
44
- p1 = FilePath.new("a")
45
- p2 = FilePath.new("b")
43
+ it "is deprecated but performs as Filepath#/" do
44
+ p1 = Filepath.new("a")
45
+ p2 = Filepath.new("b")
46
46
 
47
47
  p1.should_receive(:warn).with(/is deprecated/)
48
48
  (p1 + p2).should == (p1 / p2)
@@ -74,7 +74,7 @@ describe FilePath do
74
74
  ]
75
75
  test_data.each do |path, result|
76
76
  it "says that `#{result}` is the filename of `#{path}`" do
77
- ph = FilePath.new(path)
77
+ ph = Filepath.new(path)
78
78
  ph.filename.should == result
79
79
  end
80
80
  end
@@ -90,7 +90,7 @@ describe FilePath do
90
90
  ]
91
91
  test_data.each do |path, result|
92
92
  it "says that `#{result}` is the parent dir of `#{path}`" do
93
- ph = FilePath.new(path)
93
+ ph = Filepath.new(path)
94
94
  ph.parent_dir.should == result
95
95
  end
96
96
  end
@@ -108,7 +108,7 @@ describe FilePath do
108
108
  ]
109
109
  test_data.each do |path, base, result|
110
110
  it "says that `#{path}` relative to `#{base}` is `#{result}`" do
111
- ph = FilePath.new(path)
111
+ ph = Filepath.new(path)
112
112
  ph.relative_to(base).should == result
113
113
  end
114
114
  end
@@ -121,7 +121,7 @@ describe FilePath do
121
121
  ]
122
122
  test_data2.each do |path, base|
123
123
  it "raise an exception because `#{path}` and `#{base}` have different prefixes" do
124
- ph = FilePath.new(path)
124
+ ph = Filepath.new(path)
125
125
  expect { ph.relative_to(base) }.to raise_error(ArgumentError)
126
126
  end
127
127
  end
@@ -137,7 +137,7 @@ describe FilePath do
137
137
  ]
138
138
  test_data.each do |path, base, result|
139
139
  it "says that `#{path}` relative to the file `#{base}` is `#{result}`" do
140
- ph = FilePath.new(path)
140
+ ph = Filepath.new(path)
141
141
  ph.relative_to_file(base).should == result
142
142
  end
143
143
  end
@@ -151,7 +151,7 @@ describe FilePath do
151
151
  ]
152
152
  test_data.each do |base, new, result|
153
153
  it "changes `#{base}` + `#{new}` into `#{result}`" do
154
- ph = FilePath.new(base)
154
+ ph = Filepath.new(base)
155
155
  ph.with_filename(new).should == result
156
156
  end
157
157
  end
@@ -169,7 +169,7 @@ describe FilePath do
169
169
  ]
170
170
  test_data.each do |path, ext|
171
171
  it "says that `#{path}` has extension `#{ext}`" do
172
- FilePath.new(path).extension.should == ext
172
+ Filepath.new(path).extension.should == ext
173
173
  end
174
174
  end
175
175
  end
@@ -182,7 +182,7 @@ describe FilePath do
182
182
  ]
183
183
  with_extension.each do |path|
184
184
  it "says that <#{path}> has an extension" do
185
- FilePath.new(path).extension?.should be_true
185
+ Filepath.new(path).extension?.should be true
186
186
  end
187
187
  end
188
188
 
@@ -193,7 +193,7 @@ describe FilePath do
193
193
  ]
194
194
  no_extension.each do |path|
195
195
  it "says that <#{path}> has no extension" do
196
- FilePath.new(path).extension?.should be_false
196
+ Filepath.new(path).extension?.should be false
197
197
  end
198
198
  end
199
199
 
@@ -205,12 +205,12 @@ describe FilePath do
205
205
  ]
206
206
  extension_data.each do |path, ext|
207
207
  it "says that <#{path}> extesions is #{ext.inspect}" do
208
- FilePath.new(path).extension?(ext).should be_true
208
+ Filepath.new(path).extension?(ext).should be true
209
209
  end
210
210
  end
211
211
 
212
212
  it "says that `foo.bar` extension is not `baz`" do
213
- FilePath.new('foo.bar').extension?('baz').should be_false
213
+ Filepath.new('foo.bar').extension?('baz').should be false
214
214
  end
215
215
  end
216
216
 
@@ -224,7 +224,7 @@ describe FilePath do
224
224
  ]
225
225
  test_data.each do |path, result|
226
226
  it "replaces `#{path}` with `baz` into `#{result}`" do
227
- new = FilePath.new(path).with_extension('baz')
227
+ new = Filepath.new(path).with_extension('baz')
228
228
  new.basename.to_s.should == result
229
229
  end
230
230
  end
@@ -240,7 +240,7 @@ describe FilePath do
240
240
  ]
241
241
  test_data.each do |path, result|
242
242
  it "turns `#{path}` into `#{result}`" do
243
- new = FilePath.new(path).without_extension
243
+ new = Filepath.new(path).without_extension
244
244
  new.basename.to_s.should == result
245
245
  end
246
246
  end
@@ -248,47 +248,47 @@ describe FilePath do
248
248
 
249
249
  describe "=~" do
250
250
  it "matches `/foo/bar` with /foo/" do
251
- FilePath.new('/foo/bar').should =~ /foo/
251
+ Filepath.new('/foo/bar').should =~ /foo/
252
252
  end
253
253
 
254
254
  it "does not match `/foo/bar` with /baz/" do
255
- FilePath.new('/foo/bar').should_not =~ /baz/
255
+ Filepath.new('/foo/bar').should_not =~ /baz/
256
256
  end
257
257
 
258
258
  it "matches `/foo/bar` with /o\\/ba" do
259
- FilePath.new('/foo/bar').should =~ /o\/b/
259
+ Filepath.new('/foo/bar').should =~ /o\/b/
260
260
  end
261
261
 
262
262
  it "matches `/foo/bar/../quux` with /foo\\/quux/" do
263
- FilePath.new('/foo/bar/../quux').should =~ /foo\/quux/
263
+ Filepath.new('/foo/bar/../quux').should =~ /foo\/quux/
264
264
  end
265
265
  end
266
266
 
267
267
  describe "#root?" do
268
268
  it "says that </> points to the root directory" do
269
- FilePath.new('/').should be_root
269
+ Filepath.new('/').should be_root
270
270
  end
271
271
 
272
272
  it "says that </..> points to the root directory" do
273
- FilePath.new('/..').should be_root
273
+ Filepath.new('/..').should be_root
274
274
  end
275
275
 
276
276
  it "says that <a/b> does not point to the root directory" do
277
- FilePath.new('a/b').should_not be_root
277
+ Filepath.new('a/b').should_not be_root
278
278
  end
279
279
 
280
280
  it "says that </foo> does not point to the root directory" do
281
- FilePath.new('/foo/bar').should_not be_root
281
+ Filepath.new('/foo/bar').should_not be_root
282
282
  end
283
283
  end
284
284
 
285
285
  describe "#absolute?" do
286
286
  it "says that `/foo/bar` is absolute" do
287
- FilePath.new('/foo/bar').should be_absolute
287
+ Filepath.new('/foo/bar').should be_absolute
288
288
  end
289
289
 
290
290
  it "sasys that `foo/bar` is not absolute" do
291
- FilePath.new('foo/bar').should_not be_absolute
291
+ Filepath.new('foo/bar').should_not be_absolute
292
292
  end
293
293
  end
294
294
 
@@ -308,7 +308,7 @@ describe FilePath do
308
308
  ]
309
309
  test_data.each do |path, result|
310
310
  it "turns `#{path}` into `#{result}`" do
311
- FilePath.new(path).normalized.to_raw_string.should == result
311
+ Filepath.new(path).normalized.to_raw_string.should == result
312
312
  end
313
313
  end
314
314
  end
@@ -316,7 +316,7 @@ describe FilePath do
316
316
  describe "#each_segment" do
317
317
  it "goes through all the segments of an absolute path" do
318
318
  steps = []
319
- FilePath.new("/a/b/c").each_segment do |seg|
319
+ Filepath.new("/a/b/c").each_segment do |seg|
320
320
  steps << seg
321
321
  end
322
322
 
@@ -329,7 +329,7 @@ describe FilePath do
329
329
 
330
330
  it "goes through all the segments of a relative path" do
331
331
  steps = []
332
- FilePath.new("a/b/c").each_segment do |seg|
332
+ Filepath.new("a/b/c").each_segment do |seg|
333
333
  steps << seg
334
334
  end
335
335
 
@@ -340,7 +340,7 @@ describe FilePath do
340
340
  end
341
341
 
342
342
  it "returns the path itself" do
343
- path = FilePath.new("/a/b/c/")
343
+ path = Filepath.new("/a/b/c/")
344
344
  path.each_segment { }.should be(path)
345
345
  end
346
346
  end
@@ -348,7 +348,7 @@ describe FilePath do
348
348
  describe "#ascend" do
349
349
  it "goes through all the segments of an absolute path" do
350
350
  steps = []
351
- FilePath.new("/a/b/c").ascend do |seg|
351
+ Filepath.new("/a/b/c").ascend do |seg|
352
352
  steps << seg
353
353
  end
354
354
 
@@ -361,7 +361,7 @@ describe FilePath do
361
361
 
362
362
  it "goes through all the segments of a relative path" do
363
363
  steps = []
364
- FilePath.new("a/b/c").ascend do |seg|
364
+ Filepath.new("a/b/c").ascend do |seg|
365
365
  steps << seg
366
366
  end
367
367
 
@@ -372,7 +372,7 @@ describe FilePath do
372
372
  end
373
373
 
374
374
  it "returns the path itself" do
375
- path = FilePath.new("/a/b/c/")
375
+ path = Filepath.new("/a/b/c/")
376
376
  path.ascend { }.should be(path)
377
377
  end
378
378
  end
@@ -380,7 +380,7 @@ describe FilePath do
380
380
  describe "#descend" do
381
381
  it "goes through all the segments of an absolute path" do
382
382
  steps = []
383
- FilePath.new("/a/b/c").descend do |seg|
383
+ Filepath.new("/a/b/c").descend do |seg|
384
384
  steps << seg
385
385
  end
386
386
 
@@ -393,7 +393,7 @@ describe FilePath do
393
393
 
394
394
  it "goes through all the segments of a relative path" do
395
395
  steps = []
396
- FilePath.new("a/b/c").descend do |seg|
396
+ Filepath.new("a/b/c").descend do |seg|
397
397
  steps << seg
398
398
  end
399
399
 
@@ -404,26 +404,26 @@ describe FilePath do
404
404
  end
405
405
 
406
406
  it "returns the path itself" do
407
- path = FilePath.new("/a/b/c/")
407
+ path = Filepath.new("/a/b/c/")
408
408
  path.descend { }.should be(path)
409
409
  end
410
410
  end
411
411
 
412
412
  describe "#to_s" do
413
413
  it "works on computed absolute paths" do
414
- (FilePath.new('/') / 'a' / 'b').to_s.should eql('/a/b')
414
+ (Filepath.new('/') / 'a' / 'b').to_s.should eql('/a/b')
415
415
  end
416
416
 
417
417
  it "works on computed relative paths" do
418
- (FilePath.new('a') / 'b').to_s.should eql('a/b')
418
+ (Filepath.new('a') / 'b').to_s.should eql('a/b')
419
419
  end
420
420
 
421
421
  it "returns normalized paths" do
422
- FilePath.new("/foo/bar/..").to_s.should eql('/foo')
422
+ Filepath.new("/foo/bar/..").to_s.should eql('/foo')
423
423
  end
424
424
 
425
425
  it "returns '.' for empty paths" do
426
- FilePath.new('').to_s.should eql('.')
426
+ Filepath.new('').to_s.should eql('.')
427
427
  end
428
428
  end
429
429
 
@@ -447,7 +447,7 @@ describe FilePath do
447
447
  ]
448
448
  test_data.each do |ver1, ver2|
449
449
  it "says that `#{ver1}` is equivalent to `#{ver2}`" do
450
- ph = FilePath.new(ver1)
450
+ ph = Filepath.new(ver1)
451
451
  ph.should == ver2
452
452
  end
453
453
  end
@@ -474,7 +474,7 @@ describe FilePath do
474
474
  p1.should_not eql(p2)
475
475
  end
476
476
 
477
- it "does not match objects that are not FilePaths" do
477
+ it "does not match objects that are not Filepaths" do
478
478
  p1 = '/foo/bar/baz'.as_path
479
479
  p2 = '/foo/bar/baz'
480
480
 
@@ -524,7 +524,7 @@ describe FilePath do
524
524
  end
525
525
  end
526
526
 
527
- describe FilePath::MetadataInfo do
527
+ describe Filepath::MetadataInfo do
528
528
  describe "#stat" do
529
529
  it "returns a stat for the file" do
530
530
  (@root / 'd1').stat.should be_directory
@@ -550,7 +550,7 @@ describe FilePath do
550
550
  end
551
551
  end
552
552
 
553
- describe FilePath::MetadataChanges do
553
+ describe Filepath::MetadataChanges do
554
554
  describe "#chtime" do
555
555
  it "change mtime" do
556
556
  ph = @root / 'f1'
@@ -580,7 +580,7 @@ describe FilePath do
580
580
  end
581
581
  end
582
582
 
583
- describe FilePath::MetadataTests do
583
+ describe Filepath::MetadataTests do
584
584
  describe "#file?" do
585
585
  it "says that `f1` is a file" do
586
586
  (@root / 'f1').should be_file
@@ -675,7 +675,7 @@ describe FilePath do
675
675
  end
676
676
  end
677
677
 
678
- describe FilePath::FilesystemInfo do
678
+ describe Filepath::FilesystemInfo do
679
679
  describe "#absolute_path" do
680
680
  test_data = [
681
681
  ['d1/l11', File.expand_path('d1/l11', FIXTURES_DIR), FIXTURES_DIR],
@@ -684,7 +684,7 @@ describe FilePath do
684
684
  test_data.each do |path, abs_path, cwd|
685
685
  it "resolves <#{path}> to <#{abs_path}> (in #{cwd})" do
686
686
  Dir.chdir(cwd) do # FIXME
687
- FilePath.new(path).absolute_path.should == abs_path
687
+ Filepath.new(path).absolute_path.should == abs_path
688
688
  end
689
689
  end
690
690
  end
@@ -697,7 +697,7 @@ describe FilePath do
697
697
  end
698
698
  end
699
699
 
700
- describe FilePath::FilesystemChanges do
700
+ describe Filepath::FilesystemChanges do
701
701
  let(:ph) { @root / 'd1' / 'test-file' }
702
702
 
703
703
  before(:each) do
@@ -735,7 +735,7 @@ describe FilePath do
735
735
  end
736
736
  end
737
737
 
738
- describe FilePath::FilesystemTests do
738
+ describe Filepath::FilesystemTests do
739
739
  describe "mountpoint?" do
740
740
  it "says that </proc> is a mount point" do
741
741
  "/proc".as_path.should be_mountpoint
@@ -755,7 +755,7 @@ describe FilePath do
755
755
  end
756
756
  end
757
757
 
758
- describe FilePath::ContentInfo do
758
+ describe Filepath::ContentInfo do
759
759
  let(:ph) { @root / 'd1' / 'test-file' }
760
760
 
761
761
  before(:each) do
@@ -838,7 +838,7 @@ describe FilePath do
838
838
  end
839
839
  end
840
840
 
841
- describe FilePath::ContentChanges do
841
+ describe Filepath::ContentChanges do
842
842
  let(:ph) { @root / 'd1' / 'test-file' }
843
843
  let(:content) { "a"*20 + "b"*10 + "c"*5 }
844
844
 
@@ -922,7 +922,7 @@ describe FilePath do
922
922
  end
923
923
  end
924
924
 
925
- describe FilePath::ContentTests do
925
+ describe Filepath::ContentTests do
926
926
  let(:ph) { @root / 'd1' / 'test-file' }
927
927
 
928
928
  before(:each) do
@@ -953,7 +953,7 @@ describe FilePath do
953
953
  end
954
954
  end
955
955
 
956
- describe FilePath::SearchMethods do
956
+ describe Filepath::SearchMethods do
957
957
  describe "#entries" do
958
958
  it "raises when path is not a directory" do
959
959
  expect { (@root / 'f1').entries(:files) }.to raise_error(Errno::ENOTDIR)
@@ -1030,14 +1030,14 @@ describe FilePath do
1030
1030
  end
1031
1031
  end
1032
1032
 
1033
- describe FilePath::EnvironmentInfo
1033
+ describe Filepath::EnvironmentInfo
1034
1034
  end
1035
1035
 
1036
1036
  describe String do
1037
1037
  describe "#as_path" do
1038
- it "generates a FilePath from a String" do
1038
+ it "generates a Filepath from a String" do
1039
1039
  path = "/a/b/c".as_path
1040
- path.should be_a(FilePath)
1040
+ path.should be_a(Filepath)
1041
1041
  path.should eq("/a/b/c")
1042
1042
  end
1043
1043
  end
@@ -1045,9 +1045,9 @@ end
1045
1045
 
1046
1046
  describe Array do
1047
1047
  describe "#as_path" do
1048
- it "generates a FilePath from a String" do
1048
+ it "generates a Filepath from a String" do
1049
1049
  path = ['/', 'a', 'b', 'c'].as_path
1050
- path.should be_a(FilePath)
1050
+ path.should be_a(Filepath)
1051
1051
  path.should eq("/a/b/c")
1052
1052
  end
1053
1053
  end