filepath 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62dfbcf4f1dce1088fa0b8f2e34e90ef413007fd
4
- data.tar.gz: 5381ef6ee7a5ceb721ed6e72fc604cf4b6f9441c
3
+ metadata.gz: dc328ecf3eaa82d60d03442bf30115d7a7e94633
4
+ data.tar.gz: fdcaf08efd0cb19c50e4e6df08f29ca337c32841
5
5
  SHA512:
6
- metadata.gz: 007539ed47d49ffa9e9147eb0a8e3f8bee3dfc0196cf074fab7528dcf34e6f78536e8736c4d84cc223efacc31fbab7aeb8cd970544503df16d7e30dcdacb5fcf
7
- data.tar.gz: 4bac91223e32bfd5618a30b2e77ad5420f29b27cb21505805ae75aede7d99d2468303f43005f77b838817abb90f7aed02c18099bd560594f946bb8b78d850493
6
+ metadata.gz: 655944ebb17b86931f7b3a8503560189b85cc89f4847e5b01251344135d730e2bc6a6702e41a2f8faec9a94268e470113ccfd2520bbb339c206ff01691a1bac9
7
+ data.tar.gz: 2ea72768cf531ab78de1faec911041dc9306b38a8a1617548de67de1eb752df468012d7237f0bf2b6ea7eb0961b91e453a676cc3be176b6e51efed4c6b308c48
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.8.7"
4
3
  - "1.9.3"
5
- - "2.0.0"
6
- - jruby-18mode
7
- - jruby-19mode
8
- - rbx-19mode
4
+ - "2.1.5"
5
+ - "2.3.0"
6
+ - "2.3.3"
7
+ - jruby-9.1.9.0
8
+ sudo: false
data/README.md CHANGED
@@ -1,28 +1,28 @@
1
- FilePath
1
+ filepath
2
2
  ========
3
3
 
4
- filepath is a small library that helps dealing with files, directories and
5
- paths in general; a modern replacement for the standard Pathname.
4
+ filepath is a small library to manipulate paths; a modern replacement
5
+ for the standard Pathname.
6
6
 
7
- filepath is built around two main classes: `FilePath`, that represents paths,
8
- and `FilePathList`, lists of paths. The instances of these classes are
9
- immutable objects with dozens of convience methods for common operations such
10
- as calculating relative paths, concatenating paths, finding all the files in
11
- a directory or modifing all the extensions of a list of file names at once.
7
+ filepath is built around two main classes: `Filepath`, that represents paths,
8
+ and `FilepathList`, lists of paths. These classes provide immutable objects
9
+ with dozens of convenience methods for common operations such as calculating
10
+ relative paths, concatenating paths, finding all the files in a directory or
11
+ modifying all the extensions of a list of filenames at once.
12
12
 
13
13
 
14
14
  Features and examples
15
15
  ---------------------
16
16
 
17
- The main purpose of FilePath is to able to write
17
+ The main purpose of Filepath is to able to write
18
18
 
19
19
  require __FILE__.as_path / 'spec' / 'tasks'
20
20
 
21
- instad of cumbersome code like
21
+ instead of cumbersome code like
22
22
 
23
23
  require File.join(File.dirname(__FILE__), ['spec', 'tasks'])
24
24
 
25
- The main features of FilePath are…
25
+ The main features of Filepath are…
26
26
 
27
27
  ### Path concatenation
28
28
 
@@ -52,7 +52,7 @@ The main features of FilePath are…
52
52
 
53
53
  ### Path traversal
54
54
 
55
- file_dir = FilePath.new("/srv/example.org/web/html/")
55
+ file_dir = Filepath.new("/srv/example.org/web/html/")
56
56
  file_dir.descend do |path|
57
57
  is = path.readable? ? "is" : "is not!"
58
58
 
@@ -100,8 +100,8 @@ Requirements
100
100
  The `filepath` library does not require any external library: it relies
101
101
  complitely on functionalities available in the Ruby's core classes.
102
102
 
103
- The `filepath` library has been tested and found compatible with Ruby 1.8.7,
104
- Ruby 1.9.3 and JRuby 1.6.
103
+ The `filepath` library has been tested and found compatible with Ruby 1.9.3,
104
+ Ruby 2.3 and JRuby 9.1.x.x.
105
105
 
106
106
 
107
107
  Installation
@@ -5,19 +5,16 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "filepath"
8
- spec.version = "0.6"
8
+ spec.version = "0.7"
9
9
  spec.authors = ["Gioele Barabucci"]
10
10
  spec.email = ["gioele@svario.it"]
11
- spec.summary = "filepath is a small library that helps dealing with files, " +
12
- "directories and paths in general; a modern replacement for " +
13
- "the standard Pathname."
14
- spec.description = "filepath is built around two main classes: `FilePath`, that " +
15
- "represents paths, and `FilePathList`, lists of paths. The " +
16
- "instances of these classes are immutable objects with dozens " +
17
- "of convience methods for common operations such as calculating " +
11
+ spec.summary = "A small library to manipulate paths; a modern replacement " +
12
+ "for the standard Pathname."
13
+ spec.description = "The Filepath class provides immutable objects with dozens " +
14
+ "of convenience methods for common operations such as calculating " +
18
15
  "relative paths, concatenating paths, finding all the files in " +
19
- "a directory or modifing all the extensions of a list of file "
20
- "names at once."
16
+ "a directory or modifying all the extensions of a list of " +
17
+ "filenames at once."
21
18
  spec.homepage = "http://github.com/gioele/filepath"
22
19
  spec.license = "CC0"
23
20
 
@@ -29,4 +26,5 @@ Gem::Specification.new do |spec|
29
26
  spec.add_development_dependency "bundler", "~> 1.3"
30
27
  spec.add_development_dependency "rake"
31
28
  spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "rspec-collection_matchers"
32
30
  end
@@ -4,25 +4,25 @@
4
4
  class Array
5
5
  # Generates a path using the elements of an array as path segments.
6
6
  #
7
- # `[a, b, c].as_path` is equivalent to `FilePath.join(a, b, c)`.
7
+ # `[a, b, c].as_path` is equivalent to `Filepath.join(a, b, c)`.
8
8
  #
9
- # @example FilePath from an array of strings
9
+ # @example Filepath from an array of strings
10
10
  #
11
11
  # ["/", "foo", "bar"].as_path #=> </foo/bar>
12
12
  #
13
- # @example FilePath from an array of strings and other FilePaths
13
+ # @example Filepath from an array of strings and other Filepaths
14
14
  #
15
15
  # server_dir = config["root_dir"] / "server"
16
16
  # ["..", config_dir, "secret"].as_path #=> <../config/server/secret>
17
17
  #
18
- # @return [FilePath] a new path generated using the element as path
18
+ # @return [Filepath] a new path generated using the element as path
19
19
  # segments
20
20
  #
21
21
  # @note FIXME: `#as_path` should be `#to_path` but that method name
22
22
  # is already used
23
23
 
24
24
  def as_path
25
- FilePath.join(self)
25
+ Filepath.join(self)
26
26
  end
27
27
 
28
28
 
@@ -30,16 +30,16 @@ class Array
30
30
  #
31
31
  # The elements of the array must respond to `#as_path`.
32
32
  #
33
- # `ary.as_path` is equivalent to `FilePathList.new(ary)`.
33
+ # `ary.as_path` is equivalent to `FilepathList.new(ary)`.
34
34
  #
35
- # @return [FilePathList] a new path list containing the elements of
36
- # the array as FilePaths
35
+ # @return [FilepathList] a new path list containing the elements of
36
+ # the array as Filepaths
37
37
  #
38
38
  # @see String#as_path
39
39
  # @see Array#as_path
40
- # @see FilePath#as_path
40
+ # @see Filepath#as_path
41
41
 
42
42
  def as_path_list
43
- FilePathList.new(self)
43
+ FilepathList.new(self)
44
44
  end
45
45
  end
@@ -4,18 +4,18 @@
4
4
  class String
5
5
  # Generates a path from a String.
6
6
  #
7
- # `"/a/b/c".as_path` is equivalent to `FilePath.new("/a/b/c")`.
7
+ # `"/a/b/c".as_path` is equivalent to `Filepath.new("/a/b/c")`.
8
8
  #
9
- # @example FilePath from a string
9
+ # @example Filepath from a string
10
10
  #
11
11
  # "/etc/ssl/certs".as_path #=> </etc/ssl/certs>
12
12
  #
13
- # @return [FilePath] a new path generated from the string
13
+ # @return [Filepath] a new path generated from the string
14
14
  #
15
15
  # @note FIXME: `#as_path` should be `#to_path` but that method name
16
16
  # is already used
17
17
 
18
18
  def as_path
19
- FilePath.new(self)
19
+ Filepath.new(self)
20
20
  end
21
21
  end
@@ -1,11 +1,11 @@
1
1
  # This is free software released into the public domain (CC0 license).
2
2
 
3
3
 
4
- class FilePath
4
+ class Filepath
5
5
  SEPARATOR = '/'.freeze
6
6
 
7
7
  def initialize(path)
8
- if path.is_a? FilePath
8
+ if path.is_a? Filepath
9
9
  @segments = path.segments
10
10
  elsif path.is_a? Array
11
11
  @segments = path
@@ -18,11 +18,11 @@ class FilePath
18
18
  attr_reader :segments
19
19
 
20
20
 
21
- # Creates a FilePath joining the given segments.
21
+ # Creates a Filepath joining the given segments.
22
22
  #
23
- # @return [FilePath] a FilePath created joining the given segments
23
+ # @return [Filepath] a Filepath created joining the given segments
24
24
 
25
- def FilePath.join(*raw_paths)
25
+ def Filepath.join(*raw_paths)
26
26
  if (raw_paths.count == 1) && (raw_paths.first.is_a? Array)
27
27
  raw_paths = raw_paths.first
28
28
  end
@@ -32,7 +32,7 @@ class FilePath
32
32
  segs = []
33
33
  paths.each { |path| segs += path.segments }
34
34
 
35
- return FilePath.new(segs)
35
+ return Filepath.new(segs)
36
36
  end
37
37
 
38
38
 
@@ -42,40 +42,40 @@ class FilePath
42
42
  #
43
43
  # "a/b".as_path / "c" #=> <a/b/c>
44
44
  #
45
- # @example Append another FilePath
45
+ # @example Append another Filepath
46
46
  #
47
47
  # home = (ENV["HOME"] || "/root").as_path
48
48
  # conf_dir = '.config'.as_path
49
49
  #
50
50
  # home / conf_dir #=> </home/user/.config>
51
51
  #
52
- # @param [FilePath, String] extra_path the path to be appended to the
52
+ # @param [Filepath, String] extra_path the path to be appended to the
53
53
  # current path
54
54
  #
55
- # @return [FilePath] a new path with the given path appended
55
+ # @return [Filepath] a new path with the given path appended
56
56
 
57
57
  def /(extra_path)
58
- return FilePath.join(self, extra_path)
58
+ return Filepath.join(self, extra_path)
59
59
  end
60
60
 
61
61
 
62
62
  # Append multiple paths to the current path.
63
63
  #
64
- # @return [FilePath] a new path with all the paths appended
64
+ # @return [Filepath] a new path with all the paths appended
65
65
 
66
66
  def join(*extra_paths)
67
- return FilePath.join(self, *extra_paths)
67
+ return Filepath.join(self, *extra_paths)
68
68
  end
69
69
 
70
70
 
71
- # An alias for {FilePath#/}.
71
+ # An alias for {Filepath#/}.
72
72
  #
73
- # @deprecated Use the {FilePath#/} (slash) method instead. This method
73
+ # @deprecated Use the {Filepath#/} (slash) method instead. This method
74
74
  # does not show clearly if a path is being added or if a
75
75
  # string should be added to the filename
76
76
 
77
77
  def +(extra_path)
78
- warn "FilePath#+ is deprecated, use FilePath#/ instead."
78
+ warn "Filepath#+ is deprecated, use Filepath#/ instead."
79
79
  return self / extra_path
80
80
  end
81
81
 
@@ -102,10 +102,10 @@ class FilePath
102
102
  #
103
103
  # tmp_dir.relative_to(home_dir) #=> <../../tmp>
104
104
  #
105
- # @param [FilePath, String] base the directory to use as base for the
105
+ # @param [Filepath, String] base the directory to use as base for the
106
106
  # relative path
107
107
  #
108
- # @return [FilePath] the relative path
108
+ # @return [Filepath] the relative path
109
109
  #
110
110
  # @note this method operates on the normalized paths
111
111
  #
@@ -140,7 +140,7 @@ class FilePath
140
140
  segs = [".."] * num_parent_dirs + left_in_self
141
141
  normalized_segs = normalized_relative_segs(segs)
142
142
 
143
- return FilePath.join(normalized_segs)
143
+ return Filepath.join(normalized_segs)
144
144
  end
145
145
 
146
146
  # Calculates the relative path from a given file.
@@ -162,10 +162,10 @@ class FilePath
162
162
  #
163
163
  # tmp_dir.relative_to_file(rc_file) #=> <../../tmp>
164
164
  #
165
- # @param [FilePath, String] base_file the file to use as base for the
165
+ # @param [Filepath, String] base_file the file to use as base for the
166
166
  # relative path
167
167
  #
168
- # @return [FilePath] the relative path
168
+ # @return [Filepath] the relative path
169
169
  #
170
170
  # @see #relative_to
171
171
 
@@ -179,7 +179,7 @@ class FilePath
179
179
  # The filename is the component of a path that appears after the last
180
180
  # path separator.
181
181
  #
182
- # @return [FilePath] the filename
182
+ # @return [Filepath] the filename
183
183
 
184
184
  def filename
185
185
  segs = self.normalized_segments
@@ -197,7 +197,7 @@ class FilePath
197
197
 
198
198
  # The dir that contains the file
199
199
  #
200
- # @return [FilePath] the path of the parent dir
200
+ # @return [Filepath] the path of the parent dir
201
201
 
202
202
  def parent_dir
203
203
  return self / '..'
@@ -212,10 +212,10 @@ class FilePath
212
212
  # style = post.with_filename("style.css")
213
213
  # style.to_s #=> "posts/2012-02-16-hello-world/style.css"
214
214
  #
215
- # @param [FilePath, String] new_path the path to be put in place of
215
+ # @param [Filepath, String] new_path the path to be put in place of
216
216
  # the current filename
217
217
  #
218
- # @return [FilePath] a path with the supplied path instead of the
218
+ # @return [Filepath] a path with the supplied path instead of the
219
219
  # current filename
220
220
  #
221
221
  # @see #filename
@@ -311,7 +311,7 @@ class FilePath
311
311
  #
312
312
  # @param [String] new_ext the new extension
313
313
  #
314
- # @return [FilePath] a new path with the replaced extension
314
+ # @return [Filepath] a new path with the replaced extension
315
315
  #
316
316
  # @overload with_extension
317
317
  # Removes the file extension if present.
@@ -325,7 +325,7 @@ class FilePath
325
325
  # post_url = post_file.with_extension(nil)
326
326
  # post_url.to_s #=> "post/welcome"
327
327
  #
328
- # @return [FilePath] a new path without the extension
328
+ # @return [Filepath] a new path without the extension
329
329
 
330
330
  def with_extension(new_ext) # FIXME: accept block
331
331
  orig_filename = filename.to_s
@@ -349,7 +349,7 @@ class FilePath
349
349
  segs = @segments[0..-2]
350
350
  segs << new_filename
351
351
 
352
- return FilePath.new(segs)
352
+ return Filepath.new(segs)
353
353
  end
354
354
 
355
355
  alias :replace_extension :with_extension
@@ -365,7 +365,7 @@ class FilePath
365
365
  # post_url = post_file.without_extension
366
366
  # post_url.to_s #=> "post/welcome"
367
367
  #
368
- # @return [FilePath] a new path without the extension
368
+ # @return [Filepath] a new path without the extension
369
369
  #
370
370
  # @see #with_extension
371
371
 
@@ -454,11 +454,11 @@ class FilePath
454
454
  #
455
455
  # FIXME: document what normal form is.
456
456
  #
457
- # @return [FilePath] a new path that does not contain `.` or `..`
457
+ # @return [Filepath] a new path that does not contain `.` or `..`
458
458
  # segments.
459
459
 
460
460
  def normalized
461
- return FilePath.join(self.normalized_segments)
461
+ return Filepath.join(self.normalized_segments)
462
462
  end
463
463
 
464
464
  alias :normalised :normalized
@@ -483,7 +483,7 @@ class FilePath
483
483
  #
484
484
  # @yield [path] TODO
485
485
  #
486
- # @return [FilePath] the path itself.
486
+ # @return [Filepath] the path itself.
487
487
  #
488
488
  # @see #ascend
489
489
  # @see #descend
@@ -519,7 +519,7 @@ class FilePath
519
519
  #
520
520
  # @yield [path] TODO
521
521
  #
522
- # @return [FilePath] the path itself.
522
+ # @return [Filepath] the path itself.
523
523
  #
524
524
  # @see #each_segment
525
525
  # @see #descend
@@ -553,7 +553,7 @@ class FilePath
553
553
  #
554
554
  # @yield [path] TODO
555
555
  #
556
- # @return [FilePath] the path itself.
556
+ # @return [Filepath] the path itself.
557
557
  #
558
558
  # @see #each_segment
559
559
  # @see #ascend
@@ -568,7 +568,7 @@ class FilePath
568
568
  max_depth ||= @segments.length
569
569
  (1..max_depth).send(method) do |limit|
570
570
  segs = @segments.take(limit)
571
- yield FilePath.join(segs)
571
+ yield Filepath.join(segs)
572
572
  end
573
573
 
574
574
  return self
@@ -609,7 +609,7 @@ class FilePath
609
609
  end
610
610
 
611
611
 
612
- # @return [FilePath] the path itself.
612
+ # @return [Filepath] the path itself.
613
613
  def as_path
614
614
  self
615
615
  end
@@ -639,7 +639,7 @@ class FilePath
639
639
  # path1 == path2.parent_dir #=> true
640
640
  # path1 == path3 #=> true
641
641
  #
642
- # @param [FilePath, String] other the other path to compare
642
+ # @param [Filepath, String] other the other path to compare
643
643
  #
644
644
  # @return [boolean] whether the other path is equivalent to the current path
645
645
  #
@@ -928,7 +928,7 @@ class FilePath
928
928
  glob /= pattern
929
929
 
930
930
  raw_entries = Dir.glob(glob)
931
- entries = FilePathList.new(raw_entries)
931
+ entries = FilepathList.new(raw_entries)
932
932
 
933
933
  return entries
934
934
  end
@@ -960,7 +960,7 @@ class FilePath
960
960
  end
961
961
 
962
962
  module EnvironmentInfo
963
- def FilePath.getwd
963
+ def Filepath.getwd
964
964
  return Dir.getwd.as_path
965
965
  end
966
966
  end