pleasant_path 1.2.0 → 1.3.0

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,6 +1,6 @@
1
1
  class String
2
2
 
3
- # Converts the string to a +Pathname+ object.
3
+ # Constructs a Pathname from the String.
4
4
  #
5
5
  # @example
6
6
  # "path/to/file".to_pathname # == Pathname.new("path/to/file")
@@ -15,8 +15,8 @@ class String
15
15
  # @return [Pathname]
16
16
  alias :path :to_pathname
17
17
 
18
- # Joins the string and the argument with a directory separator (a la
19
- # +File.join+) and returns the result as a +Pathname+ object.
18
+ # Constructs a Pathname from the String, and appends +child+ to the
19
+ # Pathname.
20
20
  #
21
21
  # @example
22
22
  # "path/to" / "file" # == Pathname.new("path/to/file")
@@ -27,11 +27,16 @@ class String
27
27
  self.path / child
28
28
  end
29
29
 
30
- # Treating the string as a path, joins the parent (+dirname+) of the
31
- # path with the argument, and returns the result as a +Pathname+
32
- # object. The mnemonic for this operator is that the resultant path
33
- # goes up one directory level from the original, then goes down to the
34
- # directory specified by the argument. See also {Pathname#^}.
30
+ # @deprecated Use {Pathname#^}.
31
+ #
32
+ # Constructs a Pathname from the String, and appends +sibling+ to the
33
+ # +dirname+ of the Pathname.
34
+ #
35
+ # The mnemonic for this operator is that the result is formed by going
36
+ # up one directory level from the original path, then going back down
37
+ # to +sibling+.
38
+ #
39
+ # @see Pathname#^
35
40
  #
36
41
  # @example
37
42
  # "path/to/file1" ^ "file2" # == Pathname.new("path/to/file2")
@@ -42,9 +47,12 @@ class String
42
47
  self.path ^ sibling
43
48
  end
44
49
 
45
- # Treats the string as a filename pattern, and expands the pattern
46
- # into matching paths as +Pathname+ objects. See also +Dir.glob+ and
47
- # +Pathname.glob+.
50
+ # @deprecated Use +Pathname.glob+.
51
+ #
52
+ # Returns an array of Pathnames which match the filename pattern
53
+ # contained in the String.
54
+ #
55
+ # @see https://docs.ruby-lang.org/en/trunk/Pathname.html#method-i-glob Pathname.glob
48
56
  #
49
57
  # @example
50
58
  # "*.txt".glob # == Pathname.glob("*.txt")
@@ -54,24 +62,28 @@ class String
54
62
  Pathname.glob(self)
55
63
  end
56
64
 
57
- # Writes the string to the given file, and returns the string. The
58
- # file is overwritten if it already exists. Any necessary parent
59
- # directories are created if they do not exist.
65
+ # Writes the String to the specified +file+, overwriting the file if
66
+ # it exists. Creates the file if it does not exist, including
67
+ # any necessary parent directories. Returns the String.
68
+ #
69
+ # @see Pathname#write_text
60
70
  #
61
71
  # @example
62
72
  # "hello world".write_to_file("out.txt") # == "hello world"
63
73
  # File.read("out.txt") # == "hello world"
64
74
  #
65
75
  # @param file [String, Pathname]
66
- # @return [String]
76
+ # @return [self]
67
77
  def write_to_file(file)
68
78
  file.to_pathname.write_text(self)
69
79
  self
70
80
  end
71
81
 
72
- # Appends the string to the given file, and returns the string. The
73
- # file is created if it does not exist. Any necessary parent
74
- # directories are created if they do not exist.
82
+ # Appends the String to the specified +file+. Creates the file if it
83
+ # does not exist, including any necessary parent directories. Returns
84
+ # the String.
85
+ #
86
+ # @see Pathname#append_text
75
87
  #
76
88
  # @example
77
89
  # "hello".append_to_file("out.txt") # == "hello"
@@ -80,7 +92,7 @@ class String
80
92
  # File.read("out.txt") # == "hello world"
81
93
  #
82
94
  # @param file [String, Pathname]
83
- # @return [String]
95
+ # @return [self]
84
96
  def append_to_file(file)
85
97
  file.to_pathname.append_text(self)
86
98
  self
@@ -1,3 +1,3 @@
1
1
  module PleasantPath
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Object
2
4
 
3
- # Dumps the Object as YAML, and writes the YAML to the specified file.
4
- # Returns the Object unmodified.
5
+ # Writes the Object serialized as YAML to the specified +file+,
6
+ # overwriting the file if it exists. Creates the file if it does not
7
+ # exist, including any necessary parent directories. Returns the
8
+ # Object, unmodified.
5
9
  #
6
- # For information about available options see
7
- # {https://ruby-doc.org/stdlib/libdoc/psych/rdoc/Psych.html#method-c-dump
10
+ # For information about +options+ see
11
+ # {https://docs.ruby-lang.org/en/trunk/Psych.html#method-c-dump
8
12
  # +YAML.dump+}.
9
13
  #
10
14
  # @example
@@ -12,7 +16,7 @@ class Object
12
16
  # File.read("out.yaml") # == "---\nkey: value\n"
13
17
  #
14
18
  # @param file [String, Pathname]
15
- # @param options [Hash]
19
+ # @param options [Hash<Symbol, Object>]
16
20
  # @return [self]
17
21
  def write_to_yaml(file, options = {})
18
22
  file.to_pathname.make_dirname.open("w") do |f|
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Pathname
2
4
 
3
- # Reads the contents of the file indicated by the Pathname, and parses
4
- # it as YAML. The returned result will be a basic Ruby data
5
- # structure, namely, one of: +nil+, +true+, +false+, a +Numeric+, a
6
- # +String+, an +Array+, or a +Hash+.
5
+ # Parses the contents of the file indicated by the Pathname as YAML.
6
+ # The returned result will composed of only basic data types, e.g.
7
+ # +nil+, +true+, +false+, +Numeric+, +String+, +Array+, and +Hash+.
7
8
  #
8
9
  # @example
9
10
  # File.write("in.yaml", "key: value")
@@ -12,14 +13,20 @@ class Pathname
12
13
  #
13
14
  # @return [nil, true, false, Numeric, String, Array, Hash]
14
15
  def read_yaml
15
- self.open("r"){|f| YAML.safe_load(f, [], [], false, self) }
16
+ self.open("r") do |f|
17
+ # HACK fix Ruby 2.6 warning, but still support Ruby < 2.6
18
+ if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("3.1.0.pre1")
19
+ YAML.safe_load(f, filename: self)
20
+ else
21
+ YAML.safe_load(f, [], [], false, self)
22
+ end
23
+ end
16
24
  end
17
25
 
18
- # Reads the contents of the file indicated by the Pathname, and parses
19
- # it as YAML. The parser will use type information embedded in the
20
- # YAML to deserialize custom types. This is *UNSAFE* for YAML from
21
- # an untrusted source. To consume untrusted YAML, use
22
- # {Pathname#read_yaml} instead.
26
+ # Parses the contents of the file indicated by the Pathname as YAML,
27
+ # deserializing arbitrary data types via type information embedded in
28
+ # the YAML. This is *UNSAFE* for YAML from an untrusted source. To
29
+ # consume untrusted YAML, use {Pathname#read_yaml} instead.
23
30
  #
24
31
  # @example
25
32
  # Point = Struct.new(:x, :y)
@@ -28,7 +35,7 @@ class Pathname
28
35
  #
29
36
  # Pathname.new("in.yaml").load_yaml # == Point.new(10, 20)
30
37
  #
31
- # @return deserialized object
38
+ # @return [Object]
32
39
  def load_yaml
33
40
  YAML.load_file(self)
34
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pleasant_path
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Hefner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-18 00:00:00.000000000 Z
11
+ date: 2019-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/pleasant_path.rb
84
- - lib/pleasant_path/array.rb
84
+ - lib/pleasant_path/enumerable.rb
85
85
  - lib/pleasant_path/file.rb
86
86
  - lib/pleasant_path/io.rb
87
87
  - lib/pleasant_path/json.rb
@@ -113,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.7.6
116
+ rubygems_version: 3.0.1
118
117
  signing_key:
119
118
  specification_version: 4
120
119
  summary: A fluent API for pleasant file IO.
@@ -1,37 +0,0 @@
1
- class Array
2
-
3
- # Writes the array as lines to the given file, and returns the array.
4
- # A new line character (<code>$/</code>) is written after each line.
5
- # The file is overwritten if it already exists. Any necessary parent
6
- # directories are created if they do not exist.
7
- #
8
- # @example
9
- # [:one, :two].write_to_file("out.txt") # == [:one, :two]
10
- # File.read("out.txt") # == "one\ntwo\n"
11
- #
12
- # @param file [String, Pathname]
13
- # @return [Array]
14
- def write_to_file(file)
15
- file.to_pathname.write_lines(self)
16
- self
17
- end
18
-
19
- # Appends the array as lines to the given file, and returns the array.
20
- # A new line character (<code>$/</code>) is written after each line.
21
- # The file is created if it does not exist. Any necessary parent
22
- # directories are created if they do not exist.
23
- #
24
- # @example
25
- # [:one, :two].append_to_file("out.txt") # == [:one, :two]
26
- # File.read("out.txt") # == "one\ntwo\n"
27
- # [:three, :four].append_to_file("out.txt") # == [:three, :four]
28
- # File.read("out.txt") # == "one\ntwo\nthree\nfour\n"
29
- #
30
- # @param file [String, Pathname]
31
- # @return [Array]
32
- def append_to_file(file)
33
- file.to_pathname.append_lines(self)
34
- self
35
- end
36
-
37
- end