pleasant_path 1.3.0 → 3.0.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.
@@ -2,9 +2,9 @@
2
2
 
3
3
  class Pathname
4
4
 
5
- # {https://docs.ruby-lang.org/en/trunk/File/File/Constants.html#NULL +File::NULL+}
6
- # as a Pathname. On POSIX systems, this should be equivalent to
7
- # +Pathname.new("/dev/null")+.
5
+ # {https://docs.ruby-lang.org/en/master/File/File/Constants.html#NULL
6
+ # +File::NULL+} as a Pathname. On POSIX systems, this should be
7
+ # equivalent to +Pathname.new("/dev/null")+.
8
8
  NULL = Pathname.new(File::NULL)
9
9
 
10
10
  # Returns the Pathname unmodified. Exists for parity with
@@ -15,7 +15,7 @@ class Pathname
15
15
  self
16
16
  end
17
17
 
18
- # Joins the Pathname +dirname+ with the given +sibling+.
18
+ # Joins the Pathname's +dirname+ with the given +sibling+.
19
19
  #
20
20
  # The mnemonic for this operator is that the result is formed by going
21
21
  # up one directory level from the original path, then going back down
@@ -30,18 +30,17 @@ class Pathname
30
30
  self.dirname / sibling
31
31
  end
32
32
 
33
- # Returns the +basename+ of the parent directory (+dirname+).
33
+ # Returns the +basename+ of the Pathname's +dirname+.
34
34
  #
35
35
  # @example
36
- # Pathname.new("path/to/file").parentname # == Pathname.new("to")
36
+ # Pathname.new("grand/parent/base").parentname # == Pathname.new("parent")
37
37
  #
38
38
  # @return [Pathname]
39
39
  def parentname
40
40
  self.dirname.basename
41
41
  end
42
42
 
43
- # Returns the Pathname if +exist?+ returns true, otherwise returns
44
- # nil.
43
+ # Returns the Pathname if +exist?+ is true, otherwise returns nil.
45
44
  #
46
45
  # @example
47
46
  # FileUtils.mkdir("dir1")
@@ -84,15 +83,8 @@ class Pathname
84
83
  # @return [Boolean]
85
84
  alias :dir? :directory?
86
85
 
87
- # @deprecated Use +Pathname#empty?+.
88
- #
89
- # Alias of +Pathname#empty?+.
90
- #
91
- # @return [Boolean]
92
- alias :dir_empty? :empty?
93
-
94
- # Returns the immediate child directories of the directory indicated
95
- # by the Pathname. Returned Pathnames are prefixed by the original
86
+ # Returns the direct child directories of the directory indicated by
87
+ # the Pathname. Returned Pathnames are prefixed by the original
96
88
  # Pathname.
97
89
  #
98
90
  # @example
@@ -142,18 +134,18 @@ class Pathname
142
134
  # directory indicated by the Pathname. Iterated Pathnames are
143
135
  # prefixed by the original Pathname, and are in depth-first order.
144
136
  #
145
- # If no block is given, this method returns an Enumerator. Otherwise,
146
- # the block is called with each descendent Pathname, and this method
147
- # returns the original Pathname.
148
- #
149
- # @see https://docs.ruby-lang.org/en/trunk/Pathname.html#method-i-find Pathname#find
137
+ # If a block is given, each descendent Pathname is yielded, and this
138
+ # method returns the original Pathname. Otherwise, an Enumerator is
139
+ # returned.
150
140
  #
151
- # @overload find_dirs()
152
- # @return [Enumerator<Pathname>]
141
+ # @see https://docs.ruby-lang.org/en/master/Pathname.html#method-i-find Pathname#find
153
142
  #
154
143
  # @overload find_dirs(&block)
155
144
  # @yieldparam descendent [Pathname]
156
- # @return [Pathname]
145
+ # @return [self]
146
+ #
147
+ # @overload find_dirs()
148
+ # @return [Enumerator<Pathname>]
157
149
  def find_dirs
158
150
  return to_enum(__method__) unless block_given?
159
151
 
@@ -168,7 +160,7 @@ class Pathname
168
160
  self
169
161
  end
170
162
 
171
- # Returns the immediate child files of the directory indicated by the
163
+ # Returns the direct child files of the directory indicated by the
172
164
  # Pathname. Returned Pathnames are prefixed by the original Pathname.
173
165
  #
174
166
  # @example
@@ -218,18 +210,18 @@ class Pathname
218
210
  # indicated by the Pathname. Iterated Pathnames are prefixed by the
219
211
  # original Pathname, and are in depth-first order.
220
212
  #
221
- # If no block is given, this method returns an Enumerator. Otherwise,
222
- # the block is called with each descendent Pathname, and this method
223
- # returns the original Pathname.
213
+ # If a block is given, each descendent Pathname is yielded, and this
214
+ # method returns the original Pathname. Otherwise, an Enumerator is
215
+ # returned.
224
216
  #
225
- # @see https://docs.ruby-lang.org/en/trunk/Pathname.html#method-i-find Pathname#find
226
- #
227
- # @overload find_files()
228
- # @return [Enumerator<Pathname>]
217
+ # @see https://docs.ruby-lang.org/en/master/Pathname.html#method-i-find Pathname#find
229
218
  #
230
219
  # @overload find_files(&block)
231
220
  # @yieldparam descendent [Pathname]
232
- # @return [Pathname]
221
+ # @return [self]
222
+ #
223
+ # @overload find_files()
224
+ # @return [Enumerator<Pathname>]
233
225
  def find_files
234
226
  return to_enum(__method__) unless block_given?
235
227
 
@@ -243,10 +235,10 @@ class Pathname
243
235
  # Changes the current working directory to the Pathname. If no block
244
236
  # is given, this method returns the Pathname. Otherwise, the block is
245
237
  # called with the Pathname, the original working directory is restored
246
- # after the block exits, this method returns the return value of the
247
- # block.
238
+ # after the block exits, and this method returns the return value of
239
+ # the block.
248
240
  #
249
- # @see https://docs.ruby-lang.org/en/trunk/Dir.html#method-c-chdir Dir.chdir
241
+ # @see https://docs.ruby-lang.org/en/master/Dir.html#method-c-chdir Dir.chdir
250
242
  #
251
243
  # @example
252
244
  # FileUtils.mkdir("dir1")
@@ -259,12 +251,12 @@ class Pathname
259
251
  # Pathname.pwd # == Pathname.new("dir1")
260
252
  #
261
253
  # @overload chdir()
262
- # @return [Pathname]
254
+ # @return [self]
263
255
  #
264
256
  # @overload chdir(&block)
265
257
  # @yieldparam working_dir [Pathname]
266
- # @yieldreturn [Object] retval
267
- # @return [retval]
258
+ # @yieldreturn [Object]
259
+ # @return [Object]
268
260
  #
269
261
  # @raise [SystemCallError]
270
262
  # if the Pathname does not point to an existing directory
@@ -282,7 +274,7 @@ class Pathname
282
274
  # Creates the directory indicated by the Pathname, including any
283
275
  # necessary parent directories. Returns the Pathname.
284
276
  #
285
- # @see https://docs.ruby-lang.org/en/trunk/Pathname.html#method-i-mkpath Pathname#mkpath
277
+ # @see https://docs.ruby-lang.org/en/master/Pathname.html#method-i-mkpath Pathname#mkpath
286
278
  #
287
279
  # @example
288
280
  # Dir.exist?("path") # == false
@@ -301,8 +293,8 @@ class Pathname
301
293
  self
302
294
  end
303
295
 
304
- # Creates the directory indicated by the Pathname +dirname+, including
305
- # any necessary parent directories. Returns the Pathname.
296
+ # Creates the directory indicated by the Pathname's +dirname+,
297
+ # including any necessary parent directories. Returns the Pathname.
306
298
  #
307
299
  # @example
308
300
  # Dir.exist?("path") # == false
@@ -336,40 +328,15 @@ class Pathname
336
328
  # Dir.exist?("path/to") # == true
337
329
  # File.exist?("path/to/file") # == true
338
330
  #
339
- # @return [Pathname]
331
+ # @return [self]
340
332
  # @raise [SystemCallError]
341
- # if the Pathname points to an existent directory
333
+ # if the Pathname points to an existing directory, or if any element
334
+ # of the +dirname+ points to an existing file (non-directory)
342
335
  def make_file
343
336
  self.make_dirname.open("a"){}
344
337
  self
345
338
  end
346
339
 
347
- # @deprecated Use {Pathname#make_file}.
348
- #
349
- # Creates the file indicated by the Pathname, including any necessary
350
- # parent directories. If the file already exists, its modification
351
- # time (mtime) and access time (atime) are updated. Returns the
352
- # Pathname.
353
- #
354
- # @see https://docs.ruby-lang.org/en/trunk/FileUtils.html#method-c-touch FileUtils.touch
355
- #
356
- # @example
357
- # Dir.exist?("path") # == false
358
- # Dir.exist?("path/to") # == false
359
- #
360
- # Pathname.new("path/to/file").touch_file # == Pathname.new("path/to/file")
361
- #
362
- # Dir.exist?("path") # == true
363
- # Dir.exist?("path/to") # == true
364
- # File.exist?("path/to/file") # == true
365
- #
366
- # @return [self]
367
- def touch_file
368
- self.make_dirname
369
- FileUtils.touch(self)
370
- self
371
- end
372
-
373
340
  # Recursively deletes the directory or file indicated by the Pathname.
374
341
  # Similar to +Pathname#rmtree+, but does not raise an exception if the
375
342
  # file does not exist. Returns the Pathname.
@@ -450,42 +417,36 @@ class Pathname
450
417
  end
451
418
 
452
419
  # Moves the file or directory indicated by the Pathname to
453
- # +destination+, in the same manner as +FileUtils.mv+. Creates any
454
- # necessary parent directories of the destination. Returns
420
+ # +destination+, in the same manner as +FileUtils.mv+. Returns
455
421
  # +destination+ as a Pathname.
456
422
  #
457
- # @see https://docs.ruby-lang.org/en/trunk/FileUtils.html#method-c-mv FileUtils.mv
423
+ # @see https://docs.ruby-lang.org/en/master/FileUtils.html#method-c-mv FileUtils.mv
458
424
  #
459
425
  # @example
460
- # File.exist?("path/to/file") # == true
461
- # Dir.exist?("other") # == false
462
- # Dir.exist?("other/dir") # == false
463
- # File.exist?("other/dir/same_file") # == false
426
+ # FileUtils.mkpath("dir/files")
427
+ # FileUtils.touch("dir/files/file1")
428
+ # FileUtils.mkpath("other_dir")
464
429
  #
465
- # Pathname.new("path/to/file").move("other/dir/same_file")
466
- # # == Pathname.new("other/dir/same_file")
430
+ # Pathname.new("dir/files").move("other_dir/same_files")
431
+ # # == Pathname.new("other_dir/same_files")
467
432
  #
468
- # File.exist?("path/to/file") # == false
469
- # Dir.exist?("other") # == true
470
- # Dir.exist?("other/dir") # == true
471
- # File.exist?("other/dir/same_file") # == true
433
+ # Dir.exist?("dir/files") # == false
434
+ # File.exist?("other_dir/same_files/file1") # == true
472
435
  #
473
436
  # @param destination [Pathname, String]
474
437
  # @return [Pathname]
475
438
  def move(destination)
476
- destination = destination.to_pathname
477
- destination.make_dirname
478
439
  FileUtils.mv(self, destination)
479
- destination
440
+ destination.to_pathname
480
441
  end
481
442
 
482
- # Moves the file or directory indicated by the Pathname to a
483
- # destination, replacing any existing file or directory.
443
+ # Moves the file or directory indicated by the Pathname to
444
+ # +destination+, replacing any existing file or directory.
484
445
  #
485
446
  # If a block is given and a file or directory does exist at the
486
447
  # destination, the block is called with the source and destination
487
448
  # Pathnames, and the return value of the block is used as the new
488
- # destination. If the block returns the source Pathname or +nil+, the
449
+ # destination. If the block returns the source Pathname or nil, the
489
450
  # move is aborted.
490
451
  #
491
452
  # Creates any necessary parent directories of the destination.
@@ -574,7 +535,7 @@ class Pathname
574
535
  File.rename(self, destination)
575
536
  else
576
537
  destination.delete!
577
- self.move(destination)
538
+ self.move(destination.make_dirname)
578
539
  end
579
540
  end
580
541
 
@@ -589,7 +550,7 @@ class Pathname
589
550
  # resultant destination, the block is called with the source and
590
551
  # destination Pathnames, and the return value of the block is used as
591
552
  # the new destination. If the block returns the source Pathname or
592
- # +nil+, the move is aborted.
553
+ # nil, the move is aborted.
593
554
  #
594
555
  # Creates any necessary parent directories of the destination.
595
556
  # Returns the destination as a Pathname (or the source Pathname in the
@@ -643,42 +604,36 @@ class Pathname
643
604
  end
644
605
 
645
606
  # Copies the file or directory indicated by the Pathname to
646
- # +destination+, in the same manner as +FileUtils.cp_r+. Creates any
647
- # necessary parent directories of the destination. Returns
607
+ # +destination+, in the same manner as +FileUtils.cp_r+. Returns
648
608
  # +destination+ as a Pathname.
649
609
  #
650
- # @see https://docs.ruby-lang.org/en/trunk/FileUtils.html#method-c-cp_r FileUtils.cp_r
610
+ # @see https://docs.ruby-lang.org/en/master/FileUtils.html#method-c-cp_r FileUtils.cp_r
651
611
  #
652
612
  # @example
653
- # File.exist?("path/to/file") # == true
654
- # Dir.exist?("other") # == false
655
- # Dir.exist?("other/dir") # == false
656
- # File.exist?("other/dir/same_file") # == false
613
+ # FileUtils.mkpath("dir/files")
614
+ # FileUtils.touch("dir/files/file1")
615
+ # FileUtils.mkpath("other_dir")
657
616
  #
658
- # Pathname.new("path/to/file").copy("other/dir/same_file")
659
- # # == Pathname.new("other/dir/same_file")
617
+ # Pathname.new("dir/files").copy("other_dir/same_files")
618
+ # # == Pathname.new("other_dir/same_files")
660
619
  #
661
- # File.exist?("path/to/file") # == true
662
- # Dir.exist?("other") # == true
663
- # Dir.exist?("other/dir") # == true
664
- # File.exist?("other/dir/same_file") # == true
620
+ # File.exist?("dir/files/file1") # == true
621
+ # File.exist?("other_dir/same_files/file1") # == true
665
622
  #
666
623
  # @param destination [Pathname, String]
667
624
  # @return [Pathname]
668
625
  def copy(destination)
669
- destination = destination.to_pathname
670
- destination.make_dirname
671
626
  FileUtils.cp_r(self, destination)
672
- destination
627
+ destination.to_pathname
673
628
  end
674
629
 
675
- # Copies the file or directory indicated by the Pathname to a
676
- # destination, replacing any existing file or directory.
630
+ # Copies the file or directory indicated by the Pathname to
631
+ # +destination+, replacing any existing file or directory.
677
632
  #
678
633
  # If a block is given and a file or directory does exist at the
679
634
  # destination, the block is called with the source and destination
680
635
  # Pathnames, and the return value of the block is used as the new
681
- # destination. If the block returns the source Pathname or +nil+, the
636
+ # destination. If the block returns the source Pathname or nil, the
682
637
  # copy is aborted.
683
638
  #
684
639
  # Creates any necessary parent directories of the destination.
@@ -760,7 +715,7 @@ class Pathname
760
715
 
761
716
  if destination
762
717
  destination.delete! unless File.identical?(self, destination)
763
- self.copy(destination)
718
+ self.copy(destination.make_dirname)
764
719
  end
765
720
 
766
721
  destination || self
@@ -775,7 +730,7 @@ class Pathname
775
730
  # resultant destination, the block is called with the source and
776
731
  # destination Pathnames, and the return value of the block is used as
777
732
  # the new destination. If the block returns the source Pathname or
778
- # +nil+, the copy is aborted.
733
+ # nil, the copy is aborted.
779
734
  #
780
735
  # Creates any necessary parent directories of the destination.
781
736
  # Returns the destination as a Pathname (or the source Pathname in the
@@ -841,7 +796,7 @@ class Pathname
841
796
  # resultant destination, the block is called with the source and
842
797
  # destination Pathnames, and the return value of the block is used as
843
798
  # the new destination. If the block returns the source Pathname or
844
- # +nil+, the rename is aborted.
799
+ # nil, the rename is aborted.
845
800
  #
846
801
  # Returns the destination as a Pathname (or the source Pathname in the
847
802
  # case that the rename is aborted).
@@ -900,7 +855,7 @@ class Pathname
900
855
  # resultant destination, the block is called with the source and
901
856
  # destination Pathnames, and the return value of the block is used as
902
857
  # the new destination. If the block returns the source Pathname or
903
- # +nil+, the rename is aborted.
858
+ # nil, the rename is aborted.
904
859
  #
905
860
  # Returns the destination as a Pathname (or the source Pathname in the
906
861
  # case that the rename is aborted).
@@ -968,9 +923,6 @@ class Pathname
968
923
  # @yieldreturn [Pathname, nil]
969
924
  # @return [Pathname]
970
925
  def rename_extname(new_extname, &block)
971
- unless new_extname.start_with?(".") || new_extname.empty?
972
- new_extname = ".#{new_extname}"
973
- end
974
926
  self.move_as(self.sub_ext(new_extname), &block)
975
927
  end
976
928
 
@@ -1016,7 +968,7 @@ class Pathname
1016
968
  self
1017
969
  end
1018
970
 
1019
- # Writes each object in +lines+ as a string plus end-of-line (EOL)
971
+ # Writes each object in +lines+ as a string plus +eol+ (end-of-line)
1020
972
  # characters to the file indicated by the Pathname, overwriting the
1021
973
  # file if it exists. Creates the file if it does not exist, including
1022
974
  # any necessary parent directories. Returns the Pathname.
@@ -1037,7 +989,7 @@ class Pathname
1037
989
  self
1038
990
  end
1039
991
 
1040
- # Appends each object in +lines+ as a string plus end-of-line (EOL)
992
+ # Appends each object in +lines+ as a string plus +eol+ (end-of-line)
1041
993
  # characters to the file indicated by the Pathname. Creates the file
1042
994
  # if it does not exist, including any necessary parent directories.
1043
995
  # Returns the Pathname.
@@ -1064,12 +1016,12 @@ class Pathname
1064
1016
  alias :read_text :read
1065
1017
 
1066
1018
  # Reads all lines from the file indicated by the Pathname, and returns
1067
- # them with all end-of-line (EOL) characters stripped.
1019
+ # them with +eol+ (end-of-line) characters stripped.
1068
1020
  #
1069
1021
  # @see IO#read_lines
1070
1022
  #
1071
1023
  # @note Not to be confused with +Pathname#readlines+, which retains
1072
- # end-of-line (EOL) characters.
1024
+ # end-of-line characters.
1073
1025
  #
1074
1026
  # @example
1075
1027
  # File.read("path/to/file") # == "one\ntwo\n"
@@ -1082,10 +1034,10 @@ class Pathname
1082
1034
  self.open("r"){|f| f.read_lines(eol: eol) }
1083
1035
  end
1084
1036
 
1085
- # Reads the entire contents of the file indicated by the Pathname as a
1086
- # string, and yields that string to the given block for editing.
1087
- # Writes the return value of the block back to the file, overwriting
1088
- # previous contents. Returns the return value of the block.
1037
+ # Reads the file indicated by the Pathname, and yields the entire
1038
+ # contents as a String to the given block for editing. Writes the
1039
+ # return value of the block back to the file, overwriting previous
1040
+ # contents. Returns the Pathname.
1089
1041
  #
1090
1042
  # @see File.edit_text
1091
1043
  #
@@ -1103,17 +1055,18 @@ class Pathname
1103
1055
  # @yield [text]
1104
1056
  # @yieldparam text [String]
1105
1057
  # @yieldreturn [String]
1106
- # @return [String]
1058
+ # @return [self]
1107
1059
  def edit_text(&block)
1108
1060
  File.edit_text(self, &block)
1061
+ self
1109
1062
  end
1110
1063
 
1111
- # Reads the entire contents of the file indicated by the Pathname as
1112
- # an array of lines, and yields that array to the given block for
1113
- # editing. Writes the return value of the block back to the file,
1114
- # overwriting previous contents. End-of-line (EOL) characters are
1115
- # stripped when reading, and appended after each line when writing.
1116
- # Returns the return value of the block.
1064
+ # Reads the file indicated by the Pathname, and yields the entire
1065
+ # contents as an Array of lines to the given block for editing.
1066
+ # Writes the return value of the block back to the file, overwriting
1067
+ # previous contents. +eol+ (end-of-line) characters are stripped from
1068
+ # each line when reading, and appended to each line when writing.
1069
+ # Returns the Pathname.
1117
1070
  #
1118
1071
  # @see File.edit_lines
1119
1072
  #
@@ -1129,9 +1082,10 @@ class Pathname
1129
1082
  # @yield [lines]
1130
1083
  # @yieldparam lines [Array<String>]
1131
1084
  # @yieldreturn [Array<String>]
1132
- # @return [Array<String>]
1085
+ # @return [self]
1133
1086
  def edit_lines(eol: $/, &block)
1134
1087
  File.edit_lines(self, eol: eol, &block)
1088
+ self
1135
1089
  end
1136
1090
 
1137
1091
  # Appends the contents of file indicated by +source+ to the file
@@ -27,41 +27,6 @@ class String
27
27
  self.path / child
28
28
  end
29
29
 
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#^
40
- #
41
- # @example
42
- # "path/to/file1" ^ "file2" # == Pathname.new("path/to/file2")
43
- #
44
- # @param sibling [Pathname, String]
45
- # @return [Pathname]
46
- def ^(sibling)
47
- self.path ^ sibling
48
- end
49
-
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
56
- #
57
- # @example
58
- # "*.txt".glob # == Pathname.glob("*.txt")
59
- #
60
- # @return [Array<Pathname>]
61
- def glob
62
- Pathname.glob(self)
63
- end
64
-
65
30
  # Writes the String to the specified +file+, overwriting the file if
66
31
  # it exists. Creates the file if it does not exist, including
67
32
  # any necessary parent directories. Returns the String.
@@ -1,3 +1,3 @@
1
1
  module PleasantPath
2
- VERSION = "1.3.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -8,15 +8,15 @@ class Object
8
8
  # Object, unmodified.
9
9
  #
10
10
  # For information about +options+ see
11
- # {https://docs.ruby-lang.org/en/trunk/Psych.html#method-c-dump
11
+ # {https://docs.ruby-lang.org/en/master/Psych.html#method-c-dump
12
12
  # +YAML.dump+}.
13
13
  #
14
14
  # @example
15
- # { "key" => "value" }.write_to_yaml("out.yaml") # == { "key" => "value" }
16
- # File.read("out.yaml") # == "---\nkey: value\n"
15
+ # { "key" => "value" }.write_to_yaml("file.yaml") # == { "key" => "value" }
16
+ # File.read("file.yaml") # == "---\nkey: value\n"
17
17
  #
18
18
  # @param file [String, Pathname]
19
- # @param options [Hash<Symbol, Object>]
19
+ # @param options [Hash{Symbol => Object}]
20
20
  # @return [self]
21
21
  def write_to_yaml(file, options = {})
22
22
  file.to_pathname.make_dirname.open("w") do |f|
@@ -2,42 +2,36 @@
2
2
 
3
3
  class Pathname
4
4
 
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+.
5
+ # Reads the file indicated by the Pathname, and parses the contents as
6
+ # YAML. The returned result will be composed of only basic data
7
+ # types, e.g. +nil+, +true+, +false+, +Numeric+, +String+, +Array+,
8
+ # and +Hash+.
8
9
  #
9
10
  # @example
10
- # File.write("in.yaml", "key: value")
11
+ # File.write("file.yaml", "key: value")
11
12
  #
12
- # Pathname.new("in.yaml").read_yaml # == { "key" => "value" }
13
+ # Pathname.new("file.yaml").read_yaml # == { "key" => "value" }
13
14
  #
14
15
  # @return [nil, true, false, Numeric, String, Array, Hash]
15
16
  def read_yaml
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
17
+ YAML.safe_load_file(self)
24
18
  end
25
19
 
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.
20
+ # Reads the file indicated by the Pathname, and parses the contents as
21
+ # YAML, deserializing arbitrary data types via type information
22
+ # embedded in the YAML. This is *UNSAFE* for YAML from an untrusted
23
+ # source. To consume untrusted YAML, use {read_yaml} instead.
30
24
  #
31
25
  # @example
32
26
  # Point = Struct.new(:x, :y)
33
27
  # point = Point.new(10, 20)
34
- # File.write("in.yaml", point.to_yaml)
28
+ # File.write("file.yaml", point.to_yaml)
35
29
  #
36
- # Pathname.new("in.yaml").load_yaml # == Point.new(10, 20)
30
+ # Pathname.new("file.yaml").load_yaml # == Point.new(10, 20)
37
31
  #
38
32
  # @return [Object]
39
33
  def load_yaml
40
- YAML.load_file(self)
34
+ YAML.unsafe_load_file(self)
41
35
  end
42
36
 
43
37
  end
@@ -1,27 +1,27 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'pleasant_path/version'
1
+ require_relative "lib/pleasant_path/version"
5
2
 
6
3
  Gem::Specification.new do |spec|
7
4
  spec.name = "pleasant_path"
8
5
  spec.version = PleasantPath::VERSION
9
6
  spec.authors = ["Jonathan Hefner"]
10
- spec.email = ["jonathan.hefner@gmail.com"]
7
+ spec.email = ["jonathan@hefner.pro"]
11
8
 
12
- spec.summary = %q{A fluent API for pleasant file IO.}
9
+ spec.summary = %q{Fluent API for pleasant file IO}
13
10
  spec.homepage = "https://github.com/jonathanhefner/pleasant_path"
14
11
  spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.4"
15
13
 
16
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features)/})
14
+ spec.metadata["source_code_uri"] = spec.homepage
15
+ spec.metadata["changelog_uri"] = spec.metadata["source_code_uri"] + "/blob/master/CHANGELOG.md"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(__dir__) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.start_with?("test/", ".git") }
18
21
  end
19
22
  spec.bindir = "exe"
20
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
24
  spec.require_paths = ["lib"]
22
25
 
23
- spec.add_development_dependency "bundler", "~> 1.13"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "minitest", "~> 5.0"
26
- spec.add_development_dependency "yard", "~> 0.9"
26
+ spec.add_dependency "json", ">= 2.11"
27
27
  end