pleasant_path 1.1.0 → 1.2.0

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
- SHA1:
3
- metadata.gz: ddfbea700d9c72193add267fe9a09e88bc5d99ff
4
- data.tar.gz: 7b5bce70e3faad80ac3296767a6cbd8b398a454e
2
+ SHA256:
3
+ metadata.gz: 56365c199042c351833d072a2e26985b4aceea7cb37fdd4fe8f21c038bdee6ed
4
+ data.tar.gz: dea582a2684edab33b60b3f4e3e624ff610d0a23a78fe17c62fbc71476e4c88e
5
5
  SHA512:
6
- metadata.gz: fdf0eb05a7e27313ec2f0a9016319952c65a0931371b575fa4b72dd8959efc124db7272d3fd4c2d9bc35bde095839594110ce52be48de2ec467a6439f1b0a9bc
7
- data.tar.gz: e67312af4aa40ed25954d05979983fe45a38f727c9810184e2a63eb45e7b6fb0c340ea5d765c10848143ad46cdccdd01ebefa199d06cbc576cc35fd0ae3df195
6
+ metadata.gz: 9242bc111208a89cad99db62ab0d1b01290ee9d9e59e63e2fe9a15a96fc736b67aea03b0f972cdceac46a0e95680b755db5524033357b711b128a38f0497be84
7
+ data.tar.gz: 8ee6d00eb11286b9d1e0fce25e69ced19c73e8135d2db58f24c4562184ca5a4baa56e3866f29fe522c1e3c032046e6805095f1717564f5e5beacc51d0f00da9e
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ## 1.2.0
2
+
3
+ * Added `Pathname#existence`.
4
+ * Added `Pathname#chdir`.
5
+ * Fixed `Object#write_to_yaml` to make parent directories as necessary.
6
+
7
+ ## 1.1.0
8
+
9
+ * Added `Pathname#copy` and `Pathname#copy_into`.
10
+ * Added `Pathname#rename_basename` and `Pathname#rename_extname`.
11
+ * Added `File.common_path` and `Pathname#common_path`.
12
+ * Added `Pathname::NULL`.
13
+ * Added JSON-related and YAML-related APIs.
14
+ * Fixed `File.edit_text` and `File.edit_lines` to properly truncate.
15
+
16
+ ## 1.0.0
17
+
18
+ * Initial release
data/README.md CHANGED
@@ -30,6 +30,7 @@ The following methods are available:
30
30
  - [#append_file](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_file)
31
31
  - [#append_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_lines)
32
32
  - [#append_text](http://www.rubydoc.info/gems/pleasant_path/Pathname:append_text)
33
+ - [#chdir](http://www.rubydoc.info/gems/pleasant_path/Pathname:chdir)
33
34
  - [#common_path](http://www.rubydoc.info/gems/pleasant_path/Pathname:common_path)
34
35
  - [#copy](http://www.rubydoc.info/gems/pleasant_path/Pathname:copy)
35
36
  - [#copy_into](http://www.rubydoc.info/gems/pleasant_path/Pathname:copy_into)
@@ -40,6 +41,7 @@ The following methods are available:
40
41
  - [#dirs_r](http://www.rubydoc.info/gems/pleasant_path/Pathname:dirs_r)
41
42
  - [#edit_lines](http://www.rubydoc.info/gems/pleasant_path/Pathname:edit_lines)
42
43
  - [#edit_text](http://www.rubydoc.info/gems/pleasant_path/Pathname:edit_text)
44
+ - [#existence](http://www.rubydoc.info/gems/pleasant_path/Pathname:existence)
43
45
  - [#files](http://www.rubydoc.info/gems/pleasant_path/Pathname:files)
44
46
  - [#files_r](http://www.rubydoc.info/gems/pleasant_path/Pathname:files_r)
45
47
  - [#make_dir](http://www.rubydoc.info/gems/pleasant_path/Pathname:make_dir)
File without changes
@@ -43,7 +43,7 @@ class File
43
43
  # @yieldreturn [String] new contents
44
44
  # @return [String]
45
45
  def self.edit_text(filename)
46
- self.open(filename, 'r+') do |f|
46
+ self.open(filename, "r+") do |f|
47
47
  text = yield f.read
48
48
  f.seek(0, IO::SEEK_SET)
49
49
  f.write(text)
@@ -73,7 +73,7 @@ class File
73
73
  # @yieldreturn [Array<String>] new contents
74
74
  # @return [Array<String>]
75
75
  def self.edit_lines(filename)
76
- self.open(filename, 'r+') do |f|
76
+ self.open(filename, "r+") do |f|
77
77
  lines = yield f.read_lines
78
78
  f.seek(0, IO::SEEK_SET)
79
79
  f.write_lines(lines)
@@ -18,7 +18,7 @@ class IO
18
18
  self.write(line)
19
19
  self.write($/)
20
20
  end
21
- self.write('') # write something even if no lines
21
+ self.write("") # write something even if no lines
22
22
  lines
23
23
  end
24
24
 
File without changes
@@ -52,7 +52,7 @@ class Pathname
52
52
  # @param options [Hash]
53
53
  # @return deserialized object
54
54
  def load_json(options = {})
55
- self.open('r'){|f| JSON.load(f, nil, options) }
55
+ self.open("r"){|f| JSON.load(f, nil, options) }
56
56
  end
57
57
 
58
58
  end
File without changes
@@ -14,7 +14,7 @@ class Pathname
14
14
  end
15
15
 
16
16
  # Joins the parent (+dirname+) of the Pathname with the argument. The
17
- # mnenomic for this operator is that the resultant path goes up one
17
+ # mnemonic for this operator is that the resultant path goes up one
18
18
  # directory level from the original, then goes down to the directory
19
19
  # specified by the argument.
20
20
  #
@@ -37,6 +37,22 @@ class Pathname
37
37
  self.dirname.basename
38
38
  end
39
39
 
40
+ # Returns the Pathname if +exist?+ returns true, otherwise returns
41
+ # nil.
42
+ #
43
+ # @example
44
+ # FileUtils.mkdir("dir1")
45
+ # FileUtils.touch("dir1/file1")
46
+ #
47
+ # Pathname.new("dir1/file1").existence # == Pathname.new("dir1/file1")
48
+ #
49
+ # Pathname.new("dir1/file2").existence # == nil
50
+ #
51
+ # @return [Pathname, nil]
52
+ def existence
53
+ self if self.exist?
54
+ end
55
+
40
56
  # Computes the longest path that the Pathname and +other+ have in
41
57
  # common. See also {File.common_path}.
42
58
  #
@@ -164,6 +180,48 @@ class Pathname
164
180
  self.find.select(&:file?)
165
181
  end
166
182
 
183
+ # Changes the current working directory to the directory indicated by
184
+ # the Pathname. If a block is given, it is called with the Pathname,
185
+ # and the original working directory is restored after the block
186
+ # exits.
187
+ #
188
+ # Returns the return value of the block, if one is given. Otherwise,
189
+ # returns the Pathname.
190
+ #
191
+ # Raises an exception if the directory indicated by the Pathname does
192
+ # not exist.
193
+ #
194
+ # See also +Dir::chdir+.
195
+ #
196
+ # @example
197
+ # FileUtils.mkdir("dir1")
198
+ # FileUtils.mkdir("dir2")
199
+ #
200
+ # Pathname.new("dir1").chdir # == Pathname.new("dir1")
201
+ # Pathname.pwd # == Pathname.new("dir1")
202
+ #
203
+ # Pathname.new("dir2").chdir{|path| "in #{path}" } # == "in dir2"
204
+ # Pathname.pwd # == Pathname.new("dir1")
205
+ #
206
+ # @overload chdir()
207
+ # @return [Pathname]
208
+ # @overload chdir()
209
+ # @yieldparam path [Pathname]
210
+ # @yieldreturn [Object] block_retval
211
+ # @return [block_retval]
212
+ # @raise [SystemCallError]
213
+ # if the directory does not exist
214
+ def chdir
215
+ if block_given?
216
+ Dir.chdir(self) do |dir|
217
+ yield dir.to_pathname
218
+ end
219
+ else
220
+ Dir.chdir(self)
221
+ self
222
+ end
223
+ end
224
+
167
225
  # Alias of +Pathname#mkpath+, but this method returns the Pathname.
168
226
  #
169
227
  # @example
@@ -361,7 +419,9 @@ class Pathname
361
419
  # @param new_basename [String]
362
420
  # @return [Pathname]
363
421
  def rename_basename(new_basename)
364
- self.move(self.dirname / new_basename)
422
+ new_path = self.dirname / new_basename
423
+ self.rename(new_path)
424
+ new_path
365
425
  end
366
426
 
367
427
  # Renames the file extension of the file indicated by the Pathname.
@@ -391,7 +451,9 @@ class Pathname
391
451
  unless new_extname.start_with?(".") || new_extname.empty?
392
452
  new_extname = ".#{new_extname}"
393
453
  end
394
- self.move(self.sub_ext(new_extname))
454
+ new_path = self.sub_ext(new_extname)
455
+ self.rename(new_path)
456
+ new_path
395
457
  end
396
458
 
397
459
  # Writes given text to the file indicated by the Pathname, and returns
@@ -411,7 +473,7 @@ class Pathname
411
473
  # @param text [String]
412
474
  # @return [Pathname]
413
475
  def write_text(text)
414
- self.make_dirname.open('w'){|f| f.write(text) }
476
+ self.make_dirname.open("w"){|f| f.write(text) }
415
477
  self
416
478
  end
417
479
 
@@ -432,7 +494,7 @@ class Pathname
432
494
  # @param text [String]
433
495
  # @return [Pathname]
434
496
  def append_text(text)
435
- self.make_dirname.open('a'){|f| f.write(text) }
497
+ self.make_dirname.open("a"){|f| f.write(text) }
436
498
  self
437
499
  end
438
500
 
@@ -452,7 +514,7 @@ class Pathname
452
514
  # @param lines [Enumerable<#to_s>]
453
515
  # @return [Pathname]
454
516
  def write_lines(lines)
455
- self.make_dirname.open('w'){|f| f.write_lines(lines) }
517
+ self.make_dirname.open("w"){|f| f.write_lines(lines) }
456
518
  self
457
519
  end
458
520
 
@@ -472,7 +534,7 @@ class Pathname
472
534
  # @param lines [Enumerable<#to_s>]
473
535
  # @return [Pathname]
474
536
  def append_lines(lines)
475
- self.make_dirname.open('a'){|f| f.write_lines(lines) }
537
+ self.make_dirname.open("a"){|f| f.write_lines(lines) }
476
538
  self
477
539
  end
478
540
 
@@ -496,7 +558,7 @@ class Pathname
496
558
  #
497
559
  # @return [Array<String>]
498
560
  def read_lines
499
- self.open('r'){|f| f.read_lines }
561
+ self.open("r"){|f| f.read_lines }
500
562
  end
501
563
 
502
564
  # Reads the contents of the file indicated by the Pathname into memory
@@ -563,7 +625,7 @@ class Pathname
563
625
  # @param source [String, Pathname]
564
626
  # @return [Pathname]
565
627
  def append_file(source)
566
- self.open('a'){|destination| IO::copy_stream(source, destination) }
628
+ self.open("a"){|destination| IO::copy_stream(source, destination) }
567
629
  self
568
630
  end
569
631
 
@@ -29,7 +29,7 @@ class String
29
29
 
30
30
  # Treating the string as a path, joins the parent (+dirname+) of the
31
31
  # path with the argument, and returns the result as a +Pathname+
32
- # object. The mnenomic for this operator is that the resultant path
32
+ # object. The mnemonic for this operator is that the resultant path
33
33
  # goes up one directory level from the original, then goes down to the
34
34
  # directory specified by the argument. See also {Pathname#^}.
35
35
  #
@@ -1,3 +1,3 @@
1
1
  module PleasantPath
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -15,7 +15,9 @@ class Object
15
15
  # @param options [Hash]
16
16
  # @return [self]
17
17
  def write_to_yaml(file, options = {})
18
- File.open(file, 'w'){|f| YAML.dump(self, f, options) }
18
+ file.to_pathname.make_dirname.open("w") do |f|
19
+ YAML.dump(self, f, options)
20
+ end
19
21
  self
20
22
  end
21
23
 
@@ -12,7 +12,7 @@ class Pathname
12
12
  #
13
13
  # @return [nil, true, false, Numeric, String, Array, Hash]
14
14
  def read_yaml
15
- self.open('r'){|f| YAML.safe_load(f, [], [], false, self) }
15
+ self.open("r"){|f| YAML.safe_load(f, [], [], false, self) }
16
16
  end
17
17
 
18
18
  # Reads the contents of the file indicated by the Pathname, and parses
File without changes
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.1.0
4
+ version: 1.2.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: 2017-09-05 00:00:00.000000000 Z
11
+ date: 2018-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - CHANGELOG.md
78
79
  - Gemfile
79
80
  - LICENSE.txt
80
81
  - README.md
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  version: '0'
114
115
  requirements: []
115
116
  rubyforge_project:
116
- rubygems_version: 2.6.13
117
+ rubygems_version: 2.7.6
117
118
  signing_key:
118
119
  specification_version: 4
119
120
  summary: A fluent API for pleasant file IO.