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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6e3e6a96f3381618fe73ebb4d09a95cd607f22939398eb4352da162fed9581e
4
- data.tar.gz: 995c964b867b1632d22bf58da748afadcb0a2d3824680a1c8fdcbf69fd494d1e
3
+ metadata.gz: 5e772187275bf4dea8ba22a68a973e127586a5b9c212cd47bfcf38269c8c5f66
4
+ data.tar.gz: 59e4a89da059811da874ed435c8b060e4fab05ce22765a7bf3c3a122063e7edd
5
5
  SHA512:
6
- metadata.gz: 3c0d567cbb4c9579685a4f1923b74787321d03f4118d46af4c863272ec1ef63af48e42c0cd17a6b431043bc43a32d621c810bbae9c05ca9a4933e2d8feecff31
7
- data.tar.gz: 10d3683e71e7dc881dde05622bdb1d7d53c83ce853f6376f9dc48bb53cc1150a1f67bf412bb80d7ff8717f1aaf03693c78c64d865c4c8820861b5149ae9fcdad
6
+ metadata.gz: 0f23bc5959b08ea5bd2a803ccf42379ce9229d6ab6624c8b2c2f7d287d18861e9b868c5e232fd703fc8a759381a4a1b69851efc2341293ec90fee7c61ab2818a
7
+ data.tar.gz: 6a98f6d9ba1f9b2cba59623b3124deb7b978eb63e0fe9e37b45930541feae2cba04113e1cae4cfcbc102dbecc5212736be218de396ddf4f79805b3c61971f8f6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## 3.0.0
2
+
3
+ * [BREAKING] Drop support for Ruby < 3.4
4
+ * [BREAKING] Require `json` >= 2.11
5
+
6
+
7
+ ## 2.0.0
8
+
9
+ * [BREAKING] Drop support for Ruby < 2.6
10
+ * [BREAKING] Remove `Pathname#dir_empty?`
11
+ * Use `Pathname#empty?` instead
12
+ * [BREAKING] Remove `Pathname#touch_file`
13
+ * Use `Pathname#make_file` instead
14
+ * [BREAKING] Remove `String#^`
15
+ * [BREAKING] Remove `String#glob`
16
+ * [BREAKING] Cease creating parent directories in `Pathname#move`
17
+ * [BREAKING] Cease creating parent directories in `Pathname#copy`
18
+ * [BREAKING] Cease prepending dot in `Pathname#rename_extname`
19
+ * [BREAKING] Change `Pathname#edit_text` to return the Pathname
20
+ * [BREAKING] Change `Pathname#edit_lines` to return the Pathname
21
+
22
+
1
23
  ## 1.3.0
2
24
 
3
25
  * Add `Pathname#find_dirs`
@@ -6,8 +28,8 @@
6
28
  * Add `Pathname#available_name`
7
29
  * Add `Pathname#move_as`
8
30
  * Add `Pathname#copy_as`
9
- * Add `eol` parameter to line-oriented methods (`Pathname#read_lines`,
10
- `Pathname#write_lines`, `Pathname#append_lines`, etc)
31
+ * Add `eol` parameter to line-oriented methods (e.g.
32
+ `Pathname#read_lines`, `Pathname#write_lines`, etc)
11
33
  * Move Array methods to Enumerable
12
34
  * Use `JSON.dump_default_options` and `JSON.load_default_options` in
13
35
  JSON-related API
@@ -17,16 +39,20 @@
17
39
 
18
40
  * Add `Pathname#existence`
19
41
  * Add `Pathname#chdir`
20
- * Fix `Object#write_to_yaml` to make parent directories as necessary
42
+ * Fix `Object#write_to_yaml` to create parent directories as necessary
21
43
 
22
44
 
23
45
  ## 1.1.0
24
46
 
25
- * Add `Pathname#copy` and `Pathname#copy_into`
26
- * Add `Pathname#rename_basename` and `Pathname#rename_extname`
27
- * Add `File.common_path` and `Pathname#common_path`
47
+ * Add `Pathname#copy`
48
+ * Add `Pathname#copy_into`
49
+ * Add `Pathname#rename_basename`
50
+ * Add `Pathname#rename_extname`
51
+ * Add `File.common_path`
52
+ * Add `Pathname#common_path`
28
53
  * Add `Pathname::NULL`
29
- * Add JSON-related and YAML-related APIs
54
+ * Add JSON-related API
55
+ * Add YAML-related API
30
56
  * Fix `File.edit_text` and `File.edit_lines` to properly truncate
31
57
 
32
58
 
data/Gemfile CHANGED
@@ -1,4 +1,8 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in pleasant_path.gemspec
4
4
  gemspec
5
+
6
+ gem "rake", "~> 13.0"
7
+ gem "minitest", "~> 6.0"
8
+ gem "ostruct"
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # pleasant_path
2
2
 
3
- A [fluent API] for pleasant file IO, written as extensions to core Ruby
4
- objects. See API listing below, or browse the [full documentation].
3
+ A [fluent API][] for pleasant file IO, written as extensions to core
4
+ Ruby objects. See API listing below, or browse the [full documentation][].
5
5
 
6
6
  [fluent API]: https://en.wikipedia.org/wiki/Fluent_interface
7
- [full documentation]: http://www.rubydoc.info/gems/pleasant_path/
7
+ [full documentation]: https://www.rubydoc.info/gems/pleasant_path/
8
8
 
9
9
 
10
10
  ## Examples
@@ -22,110 +22,99 @@ objects. See API listing below, or browse the [full documentation].
22
22
 
23
23
  The following methods are available:
24
24
 
25
- - [Pathname](http://www.rubydoc.info/gems/pleasant_path/Pathname)
26
- - [::NULL](http://www.rubydoc.info/gems/pleasant_path/Pathname#NULL-constant)
27
- - [#^](http://www.rubydoc.info/gems/pleasant_path/Pathname:%5E)
28
- - [#append_file](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_file)
29
- - [#append_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_lines)
30
- - [#append_text](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_text)
31
- - [#available_name](http://www.rubydoc.info/gems/pleasant_path/Pathname:available_name)
32
- - [#chdir](http://www.rubydoc.info/gems/pleasant_path/Pathname:chdir)
33
- - [#common_path](http://www.rubydoc.info/gems/pleasant_path/Pathname:common_path)
34
- - [#copy](http://www.rubydoc.info/gems/pleasant_path/Pathname:copy)
35
- - [#copy_as](http://www.rubydoc.info/gems/pleasant_path/Pathname:copy_as)
36
- - [#copy_into](http://www.rubydoc.info/gems/pleasant_path/Pathname:copy_into)
37
- - [#delete!](http://www.rubydoc.info/gems/pleasant_path/Pathname:delete%21)
38
- - [#dir?](http://www.rubydoc.info/gems/pleasant_path/Pathname:dir%3F)
39
- - [#dirs](http://www.rubydoc.info/gems/pleasant_path/Pathname:dirs)
40
- - [#dirs_r](http://www.rubydoc.info/gems/pleasant_path/Pathname:dirs_r)
41
- - [#edit_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:edit_lines)
42
- - [#edit_text](http://www.rubydoc.info/gems/pleasant_path/Pathname:edit_text)
43
- - [#existence](http://www.rubydoc.info/gems/pleasant_path/Pathname:existence)
44
- - [#files](http://www.rubydoc.info/gems/pleasant_path/Pathname:files)
45
- - [#files_r](http://www.rubydoc.info/gems/pleasant_path/Pathname:files_r)
46
- - [#find_dirs](http://www.rubydoc.info/gems/pleasant_path/Pathname:find_dirs)
47
- - [#find_files](http://www.rubydoc.info/gems/pleasant_path/Pathname:find_files)
48
- - [#make_dir](http://www.rubydoc.info/gems/pleasant_path/Pathname:make_dir)
49
- - [#make_dirname](http://www.rubydoc.info/gems/pleasant_path/Pathname:make_dirname)
50
- - [#make_file](http://www.rubydoc.info/gems/pleasant_path/Pathname:make_file)
51
- - [#move](http://www.rubydoc.info/gems/pleasant_path/Pathname:move)
52
- - [#move_as](http://www.rubydoc.info/gems/pleasant_path/Pathname:move_as)
53
- - [#move_into](http://www.rubydoc.info/gems/pleasant_path/Pathname:move_into)
54
- - [#parentname](http://www.rubydoc.info/gems/pleasant_path/Pathname:parentname)
55
- - [#read_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:read_lines)
56
- - [#rename_basename](http://www.rubydoc.info/gems/pleasant_path/Pathname:rename_basename)
57
- - [#rename_extname](http://www.rubydoc.info/gems/pleasant_path/Pathname:rename_extname)
58
- - [#to_pathname](http://www.rubydoc.info/gems/pleasant_path/Pathname:to_pathname)
59
- - [#write_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:write_lines)
60
- - [#write_text](http://www.rubydoc.info/gems/pleasant_path/Pathname:write_text)
61
- - [String](http://www.rubydoc.info/gems/pleasant_path/String)
62
- - [#/](http://www.rubydoc.info/gems/pleasant_path/String:%2F)
63
- - [#append_to_file](http://www.rubydoc.info/gems/pleasant_path/String:append_to_file)
64
- - [#path](http://www.rubydoc.info/gems/pleasant_path/String:path)
65
- - [#to_pathname](http://www.rubydoc.info/gems/pleasant_path/String:to_pathname)
66
- - [#write_to_file](http://www.rubydoc.info/gems/pleasant_path/String:write_to_file)
67
- - [Enumerable](http://www.rubydoc.info/gems/pleasant_path/Enumerable)
68
- - [#append_to_file](http://www.rubydoc.info/gems/pleasant_path/Enumerable:append_to_file)
69
- - [#write_to_file](http://www.rubydoc.info/gems/pleasant_path/Enumerable:write_to_file)
70
- - [File](http://www.rubydoc.info/gems/pleasant_path/File)
71
- - [.common_path](http://www.rubydoc.info/gems/pleasant_path/File.common_path)
72
- - [.edit_lines](http://www.rubydoc.info/gems/pleasant_path/File.edit_lines)
73
- - [.edit_text](http://www.rubydoc.info/gems/pleasant_path/File.edit_text)
74
- - [IO](http://www.rubydoc.info/gems/pleasant_path/IO)
75
- - [#read_lines](http://www.rubydoc.info/gems/pleasant_path/IO:read_lines)
76
- - [#write_lines](http://www.rubydoc.info/gems/pleasant_path/IO:write_lines)
25
+ - [`Pathname`](https://www.rubydoc.info/gems/pleasant_path/Pathname)
26
+ - [`::NULL`](https://www.rubydoc.info/gems/pleasant_path/Pathname#NULL-constant)
27
+ - [`#^`](https://www.rubydoc.info/gems/pleasant_path/Pathname:%5E)
28
+ - [`#append_file`](https://www.rubydoc.info/gems/pleasant_path/Pathname:append_file)
29
+ - [`#append_lines`](https://www.rubydoc.info/gems/pleasant_path/Pathname:append_lines)
30
+ - [`#append_text`](https://www.rubydoc.info/gems/pleasant_path/Pathname:append_text)
31
+ - [`#available_name`](https://www.rubydoc.info/gems/pleasant_path/Pathname:available_name)
32
+ - [`#chdir`](https://www.rubydoc.info/gems/pleasant_path/Pathname:chdir)
33
+ - [`#common_path`](https://www.rubydoc.info/gems/pleasant_path/Pathname:common_path)
34
+ - [`#copy`](https://www.rubydoc.info/gems/pleasant_path/Pathname:copy)
35
+ - [`#copy_as`](https://www.rubydoc.info/gems/pleasant_path/Pathname:copy_as)
36
+ - [`#copy_into`](https://www.rubydoc.info/gems/pleasant_path/Pathname:copy_into)
37
+ - [`#delete!`](https://www.rubydoc.info/gems/pleasant_path/Pathname:delete%21)
38
+ - [`#dir?`](https://www.rubydoc.info/gems/pleasant_path/Pathname:dir%3F)
39
+ - [`#dirs`](https://www.rubydoc.info/gems/pleasant_path/Pathname:dirs)
40
+ - [`#dirs_r`](https://www.rubydoc.info/gems/pleasant_path/Pathname:dirs_r)
41
+ - [`#edit_lines`](https://www.rubydoc.info/gems/pleasant_path/Pathname:edit_lines)
42
+ - [`#edit_text`](https://www.rubydoc.info/gems/pleasant_path/Pathname:edit_text)
43
+ - [`#existence`](https://www.rubydoc.info/gems/pleasant_path/Pathname:existence)
44
+ - [`#files`](https://www.rubydoc.info/gems/pleasant_path/Pathname:files)
45
+ - [`#files_r`](https://www.rubydoc.info/gems/pleasant_path/Pathname:files_r)
46
+ - [`#find_dirs`](https://www.rubydoc.info/gems/pleasant_path/Pathname:find_dirs)
47
+ - [`#find_files`](https://www.rubydoc.info/gems/pleasant_path/Pathname:find_files)
48
+ - [`#make_dir`](https://www.rubydoc.info/gems/pleasant_path/Pathname:make_dir)
49
+ - [`#make_dirname`](https://www.rubydoc.info/gems/pleasant_path/Pathname:make_dirname)
50
+ - [`#make_file`](https://www.rubydoc.info/gems/pleasant_path/Pathname:make_file)
51
+ - [`#move`](https://www.rubydoc.info/gems/pleasant_path/Pathname:move)
52
+ - [`#move_as`](https://www.rubydoc.info/gems/pleasant_path/Pathname:move_as)
53
+ - [`#move_into`](https://www.rubydoc.info/gems/pleasant_path/Pathname:move_into)
54
+ - [`#parentname`](https://www.rubydoc.info/gems/pleasant_path/Pathname:parentname)
55
+ - [`#read_lines`](https://www.rubydoc.info/gems/pleasant_path/Pathname:read_lines)
56
+ - [`#rename_basename`](https://www.rubydoc.info/gems/pleasant_path/Pathname:rename_basename)
57
+ - [`#rename_extname`](https://www.rubydoc.info/gems/pleasant_path/Pathname:rename_extname)
58
+ - [`#to_pathname`](https://www.rubydoc.info/gems/pleasant_path/Pathname:to_pathname)
59
+ - [`#write_lines`](https://www.rubydoc.info/gems/pleasant_path/Pathname:write_lines)
60
+ - [`#write_text`](https://www.rubydoc.info/gems/pleasant_path/Pathname:write_text)
61
+ - [`String`](https://www.rubydoc.info/gems/pleasant_path/String)
62
+ - [`#/`](https://www.rubydoc.info/gems/pleasant_path/String:%2F)
63
+ - [`#append_to_file`](https://www.rubydoc.info/gems/pleasant_path/String:append_to_file)
64
+ - [`#path`](https://www.rubydoc.info/gems/pleasant_path/String:path)
65
+ - [`#to_pathname`](https://www.rubydoc.info/gems/pleasant_path/String:to_pathname)
66
+ - [`#write_to_file`](https://www.rubydoc.info/gems/pleasant_path/String:write_to_file)
67
+ - [`Enumerable`](https://www.rubydoc.info/gems/pleasant_path/Enumerable)
68
+ - [`#append_to_file`](https://www.rubydoc.info/gems/pleasant_path/Enumerable:append_to_file)
69
+ - [`#write_to_file`](https://www.rubydoc.info/gems/pleasant_path/Enumerable:write_to_file)
70
+ - [`File`](https://www.rubydoc.info/gems/pleasant_path/File)
71
+ - [`.common_path`](https://www.rubydoc.info/gems/pleasant_path/File.common_path)
72
+ - [`.edit_lines`](https://www.rubydoc.info/gems/pleasant_path/File.edit_lines)
73
+ - [`.edit_text`](https://www.rubydoc.info/gems/pleasant_path/File.edit_text)
74
+ - [`IO`](https://www.rubydoc.info/gems/pleasant_path/IO)
75
+ - [`#read_lines`](https://www.rubydoc.info/gems/pleasant_path/IO:read_lines)
76
+ - [`#write_lines`](https://www.rubydoc.info/gems/pleasant_path/IO:write_lines)
77
77
 
78
78
 
79
79
  ## JSON-related and YAML-related API
80
80
 
81
- *pleasant_path* also includes methods for interacting with JSON and YAML
82
- files, using the [JSON module] and [YAML module] that are part of Ruby's
83
- standard library. Because Ruby does not load these modules by default,
84
- *pleasant_path* does not load its JSON-related and YAML-related API by
85
- default either. To load these *pleasant_path* APIs **and** the relevant
86
- standard library modules, use:
81
+ `pleasant_path` also includes methods for interacting with JSON and YAML
82
+ files, using the [JSON module][] and [YAML module][] that are part of
83
+ Ruby's standard library. Because Ruby does not load these modules by
84
+ default, `pleasant_path` does not load its JSON-related and YAML-related
85
+ API by default either. To load these `pleasant_path` APIs **and** the
86
+ relevant standard library modules, use:
87
87
 
88
88
  ```ruby
89
89
  require "pleasant_path/json"
90
90
  require "pleasant_path/yaml"
91
91
  ```
92
92
 
93
- [JSON module]: https://ruby-doc.org/stdlib/libdoc/json/rdoc/JSON.html
94
- [YAML module]: https://ruby-doc.org/stdlib/libdoc/yaml/rdoc/YAML.html
93
+ [JSON module]: https://docs.ruby-lang.org/en/master/JSON.html
94
+ [YAML module]: https://docs.ruby-lang.org/en/master/YAML.html
95
95
 
96
96
  The following methods are available:
97
97
 
98
- - Object
99
- - [write_to_json](http://www.rubydoc.info/gems/pleasant_path/Object:write_to_json)
100
- - [write_to_yaml](http://www.rubydoc.info/gems/pleasant_path/Object:write_to_yaml)
101
- - Pathname
102
- - [load_json](http://www.rubydoc.info/gems/pleasant_path/Pathname:load_json)
103
- - [load_yaml](http://www.rubydoc.info/gems/pleasant_path/Pathname:load_yaml)
104
- - [read_json](http://www.rubydoc.info/gems/pleasant_path/Pathname:read_json)
105
- - [read_yaml](http://www.rubydoc.info/gems/pleasant_path/Pathname:read_yaml)
98
+ - `Object`
99
+ - [`write_to_json`](https://www.rubydoc.info/gems/pleasant_path/Object:write_to_json)
100
+ - [`write_to_yaml`](https://www.rubydoc.info/gems/pleasant_path/Object:write_to_yaml)
101
+ - `Pathname`
102
+ - [`load_json`](https://www.rubydoc.info/gems/pleasant_path/Pathname:load_json)
103
+ - [`load_yaml`](https://www.rubydoc.info/gems/pleasant_path/Pathname:load_yaml)
104
+ - [`read_json`](https://www.rubydoc.info/gems/pleasant_path/Pathname:read_json)
105
+ - [`read_yaml`](https://www.rubydoc.info/gems/pleasant_path/Pathname:read_yaml)
106
106
 
107
107
 
108
108
  ## Installation
109
109
 
110
- Install from [Ruby Gems](https://rubygems.org/gems/pleasant_path):
111
-
112
- ```bash
113
- $ gem install pleasant_path
114
- ```
115
-
116
- Then require in your Ruby script:
117
-
118
- ```ruby
119
- require "pleasant_path"
120
- ```
110
+ Install the [`pleasant_path` gem](https://rubygems.org/gems/pleasant_path).
121
111
 
122
112
 
123
113
  ## Contributing
124
114
 
125
- Run `rake test` to run the tests. You can also run `rake irb` for an
126
- interactive prompt that pre-loads the project code.
115
+ Run `rake test` to run the tests.
127
116
 
128
117
 
129
118
  ## License
130
119
 
131
- [MIT License](https://opensource.org/licenses/MIT)
120
+ [MIT License](LICENSE.txt)
data/Rakefile CHANGED
@@ -1,18 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
- require "yard"
4
-
5
-
6
- YARD::Rake::YardocTask.new(:doc) do |t|
7
- end
8
-
9
- desc "Launch IRB with this gem pre-loaded"
10
- task :irb do
11
- require "pleasant_path"
12
- require "irb"
13
- ARGV.clear
14
- IRB.start
15
- end
16
3
 
17
4
  Rake::TestTask.new(:test) do |t|
18
5
  t.libs << "test"
@@ -1,9 +1,9 @@
1
1
  module Enumerable
2
2
 
3
- # Writes each object in the Enumerable as a string plus end-of-line
4
- # (EOL) characters to the specified +file+, overwriting the file if it
5
- # exists. Creates the file if it does not exist, including any
6
- # necessary parent directories. Returns the Enumerable.
3
+ # Writes each object in the Enumerable as a string plus +eol+
4
+ # (end-of-line) characters to the specified +file+, overwriting the
5
+ # file if it exists. Creates the file if it does not exist, including
6
+ # any necessary parent directories. Returns the Enumerable.
7
7
  #
8
8
  # @see Pathname#write_lines
9
9
  #
@@ -19,10 +19,10 @@ module Enumerable
19
19
  self
20
20
  end
21
21
 
22
- # Appends each object in the Enumerable as a string plus end-of-line
23
- # (EOL) characters to the specified +file+. Creates the file if it
24
- # does not exist, including any necessary parent directories. Returns
25
- # the Enumerable.
22
+ # Appends each object in the Enumerable as a string plus +eol+
23
+ # (end-of-line) characters to the specified +file+. Creates the file
24
+ # if it does not exist, including any necessary parent directories.
25
+ # Returns the Enumerable.
26
26
  #
27
27
  # @see Pathname#append_lines
28
28
  #
@@ -2,7 +2,7 @@
2
2
 
3
3
  class File
4
4
 
5
- # Returns the longest path that all of +paths+ have in common.
5
+ # Returns the longest path that all given +paths+ have in common.
6
6
  #
7
7
  # @example
8
8
  # File.common_path(["a/b/x", "a/b/y", "a/b/z"]) # == "a/b/"
@@ -23,10 +23,10 @@ class File
23
23
  short[0, i == short.length ? i : (last + 1)]
24
24
  end
25
25
 
26
- # Reads the entire contents of the file indicated by +filename+ as a
27
- # string, and yields that string to the given block for editing.
28
- # Writes the return value of the block back to the file, overwriting
29
- # previous contents. Returns the return value of the block.
26
+ # Reads the file indicated by +filename+, and yields the entire
27
+ # contents as a String to the given block for editing. Writes the
28
+ # return value of the block back to the file, overwriting previous
29
+ # contents. Returns the return value of the block.
30
30
  #
31
31
  # @example Update JSON data file
32
32
  # File.read("data.json") # == '{"nested":{"key":"value"}}'
@@ -54,11 +54,11 @@ class File
54
54
  end
55
55
  end
56
56
 
57
- # Reads the entire contents of the file indicated by +filename+ as an
58
- # array of lines, and yields that array to the given block for
59
- # editing. Writes the return value of the block back to the file,
60
- # overwriting previous contents. End-of-line (EOL) characters are
61
- # stripped when reading, and appended after each line when writing.
57
+ # Reads the file indicated by +filename+, and yields the entire
58
+ # contents as an Array of lines to the given block for editing.
59
+ # Writes the return value of the block back to the file, overwriting
60
+ # previous contents. +eol+ (end-of-line) characters are stripped from
61
+ # each line when reading, and appended to each line when writing.
62
62
  # Returns the return value of the block.
63
63
  #
64
64
  # @example Dedup lines of file
@@ -2,7 +2,7 @@
2
2
 
3
3
  class IO
4
4
 
5
- # Writes each object in +lines+ as a string plus end-of-line (EOL)
5
+ # Writes each object in +lines+ as a string plus +eol+ (end-of-line)
6
6
  # characters to the IO. Returns +lines+, unmodified.
7
7
  #
8
8
  # @example
@@ -14,7 +14,7 @@ class IO
14
14
  #
15
15
  # @param lines [Enumerable<#to_s>]
16
16
  # @param eol [String]
17
- # @return [Enumerable<#to_s>]
17
+ # @return [lines]
18
18
  def write_lines(lines, eol: $/)
19
19
  lines.each do |line|
20
20
  self.write(line)
@@ -24,11 +24,11 @@ class IO
24
24
  lines
25
25
  end
26
26
 
27
- # Reads all lines from the IO, and returns them with all end-of-line
28
- # (EOL) characters stripped.
27
+ # Reads all lines from the IO, and returns them with +eol+
28
+ # (end-of-line) characters stripped.
29
29
  #
30
30
  # @note Not to be confused with +IO#readlines+, which retains
31
- # end-of-line (EOL) characters.
31
+ # end-of-line characters.
32
32
  #
33
33
  # @example
34
34
  # File.read("in.txt") # == "one\ntwo\n"
@@ -6,21 +6,20 @@ class Object
6
6
  # Object, unmodified.
7
7
  #
8
8
  # For information about +options+ see
9
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#method-i-generate
10
- # +JSON.generate+}. By default, this method uses
11
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#attribute-c-dump_default_options
12
- # +JSON.dump_default_options+}.
9
+ # {https://docs.ruby-lang.org/en/master/JSON.html#method-i-generate
10
+ # +JSON.generate+}. By default, this method uses the default options
11
+ # for {https://docs.ruby-lang.org/en/master/JSON.html#method-i-dump
12
+ # +JSON.dump+}.
13
13
  #
14
14
  # @example
15
- # { "key" => "value" }.write_to_json("out.json") # == { "key" => "value" }
16
- # File.read("out.json") # == '{"key":"value"}'
15
+ # { "key" => "value" }.write_to_json("file.json") # == { "key" => "value" }
16
+ # File.read("file.json") # == '{"key":"value"}'
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_json(file, options = {})
22
- options = JSON.dump_default_options.merge(options)
23
- file.to_pathname.write_text(self.to_json(options))
22
+ file.to_pathname.write_text(JSON.dump(self, nil, nil, options))
24
23
  self
25
24
  end
26
25
 
@@ -2,36 +2,37 @@
2
2
 
3
3
  class Pathname
4
4
 
5
- # Parses the contents of the file indicated by the Pathname as JSON.
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
+ # JSON. 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
  # For information about +options+, see
10
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#method-i-parse
11
+ # {https://docs.ruby-lang.org/en/master/JSON.html#method-i-parse
11
12
  # +JSON.parse+}. By default, this method uses
12
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#attribute-c-load_default_options
13
+ # {https://docs.ruby-lang.org/en/master/JSON.html#attribute-c-load_default_options
13
14
  # +JSON.load_default_options+} plus +create_additions: false+.
14
15
  #
15
16
  # @example
16
- # File.write("in.json", '{"key": "value"}')
17
+ # File.write("file.json", '{"key": "value"}')
17
18
  #
18
- # Pathname.new("in.json").read_json # == { "key" => "value" }
19
+ # Pathname.new("file.json").read_json # == { "key" => "value" }
19
20
  #
20
- # @param options [Hash<Symbol, Object>]
21
+ # @param options [Hash{Symbol => Object}]
21
22
  # @return [nil, true, false, Numeric, String, Symbol, Array, Hash]
22
23
  def read_json(options = {})
23
24
  JSON.load(self, nil, { create_additions: false, **options })
24
25
  end
25
26
 
26
- # Parses the contents of the file indicated by the Pathname as JSON,
27
- # deserializing arbitrary data types via type information embedded in
28
- # the JSON. This is *UNSAFE* for JSON from an untrusted source. To
29
- # consume untrusted JSON, use {Pathname#read_json} instead.
27
+ # Reads the file indicated by the Pathname, and parses the contents as
28
+ # JSON, deserializing arbitrary data types via type information
29
+ # embedded in the JSON. This is *UNSAFE* for JSON from an untrusted
30
+ # source. To consume untrusted JSON, use {read_json} instead.
30
31
  #
31
32
  # For information about +options+, see
32
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#method-i-parse
33
+ # {https://docs.ruby-lang.org/en/master/JSON.html#method-i-parse
33
34
  # +JSON.parse+}. By default, this method uses
34
- # {https://docs.ruby-lang.org/en/trunk/JSON.html#attribute-c-load_default_options
35
+ # {https://docs.ruby-lang.org/en/master/JSON.html#attribute-c-load_default_options
35
36
  # +JSON.load_default_options+}.
36
37
  #
37
38
  # For information about serializing custom types to JSON, see the
@@ -42,14 +43,14 @@ class Pathname
42
43
  # require "json/add/core" # provides Struct#to_json
43
44
  # Point = Struct.new(:x, :y)
44
45
  # point = Point.new(10, 20)
45
- # File.write("in.json", point.to_json)
46
+ # File.write("file.json", point.to_json)
46
47
  #
47
- # Pathname.new("in.json").load_json # == Point.new(10, 20)
48
+ # Pathname.new("file.json").load_json # == Point.new(10, 20)
48
49
  #
49
- # @param options [Hash<Symbol, Object>]
50
+ # @param options [Hash{Symbol => Object}]
50
51
  # @return [Object]
51
52
  def load_json(options = {})
52
- JSON.load(self, nil, options)
53
+ JSON.load(self, nil, { create_additions: true, **options })
53
54
  end
54
55
 
55
56
  end