refinements 7.15.1 → 7.16.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
2
  SHA256:
3
- metadata.gz: c4efd7acd4d8da05214aa7947c0f61f3a04c8ece8733c2bdc4dc48ce9cbad371
4
- data.tar.gz: 5025123a8cc9e8fe23d1a0436e265c173a89477e6b5194a159a1ed9e5cb5ec9c
3
+ metadata.gz: 27c7f3818bd1f3d0d3fc39cb4c8721097d5003176b54710888deba6d012b4f77
4
+ data.tar.gz: f607fea47fce94c11c3ab7dcc6603b169567133fbbe6ca76fb0af0c9fa0196e4
5
5
  SHA512:
6
- metadata.gz: 48228ed81040b9e9b18f7e743d3cdb64885ea53515de5d588817a8969d6d02781e7404b8a6e33e7f24c70f982c3b3f5fd72b61ceb1c87a5d2c8eb8117e544641
7
- data.tar.gz: 1d0a4c17a13822cea9d33b2dbdc937e1ea34559910821224b41230b1ac5ab4873f55b423d456fde87866befad8494972963f92dcddf188c996a6d04e8488ba2b
6
+ metadata.gz: da5ff60dc1e6d4055adc850bbe7aa48d02c148f17fb42c9e50f939d577d506097603c2790cf5ce040cce1cb8389e28ebd363d3318d1224d06df4fc6d36e56b3f
7
+ data.tar.gz: a5a96d51b0e95d1f603262ca8ce767969e3faca18645327f368d8ee03aed7d0fa27211d9e35a8af30bcc6ca86d6dad33d804a4c9f1b830789b39b06dc0791793
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -546,10 +546,79 @@ construct a valid path.
546
546
  Pathname(nil) # => Pathname("")
547
547
  ----
548
548
 
549
+ ===== .home
550
+
551
+ Answers user home directory.
552
+
553
+ [source,ruby]
554
+ ----
555
+ Pathname.home # => Pathname "/Users/bkuhlmann"
556
+ ----
557
+
558
+ ===== .make_temp_dir
559
+
560
+ Wraps `Dir.mktmpdir` with the following behavior (see
561
+ link:https://rubyapi.org/o/Dir.mktmpdir#method-c-mktmpdir[Dir.mktmpdir] for details):
562
+
563
+ * *Without Block* - Answers a newly created Pathname instance which is not automatically cleaned up.
564
+ * *With Block* Yields a Pathname instance, answers result of given block, and automatidally cleans
565
+ up temporary directory after block exits.
566
+
567
+ The following examples use truncated temporary directories for illustration purposes only. In
568
+ reality, these paths will be longer depending on which operating system you are using.
569
+
570
+ [source,ruby]
571
+ ----
572
+ Pathname.make_temp_dir # => Pathname:/var/folders/T/temp-20200101-16940-r8
573
+ Pathname.make_temp_dir prefix: "prefix-" # => Pathname:/var/folders/T/prefix-20200101-16940-r8
574
+ Pathname.make_temp_dir suffix: "-suffix" # => Pathname:/var/folders/T/temp-20200101-16940-r8-suffix
575
+ Pathname.make_temp_dir prefix: "prefix-", suffix: "-suffix" # => Pathname:/var/folders/T/prefix-20200101-16940-r8-suffix
576
+ Pathname.make_temp_dir root: "/example" # => Pathname:/example/temp-20200101-16940-r8
577
+ Pathname.make_temp_dir { "I am a block result" } # => "I am a block result"
578
+ Pathname.make_temp_dir { |path| path.join "sub_dir" } # => Pathname:/var/folders/T/temp-20200101-16940-r8/sub_dir
579
+ ----
580
+
581
+ ===== .require_tree
582
+
583
+ Requires all files in given root path and corresponding nested tree structure. All files are sorted
584
+ before being required to ensure consistent behavior. Example:
585
+
586
+ [source,rby]
587
+ ----
588
+ # Before
589
+ Dir[File.join(__dir__, "support/shared_contexts/**/*.rb")].sort.each { |path| require path }
590
+
591
+ # After
592
+ Pathname.require_tree __dir__, "support/shared_contexts/**/*.rb"
593
+ ----
594
+
595
+ The following are further examples of potential usage:
596
+
597
+ [source,ruby]
598
+ ----
599
+ # Requires all files in root directory and below.
600
+ Pathname.require_tree __dir__
601
+
602
+ # Requires all files in `/test/**/*.rb` and below.
603
+ Pathname.require_tree "/test"
604
+
605
+ # Requires all files in RSpec shared examples directory structure.
606
+ Pathname.require_tree Bundler.root.join("spec"), "support/shared_examples/**/*.rb"
607
+ ----
608
+
609
+ ===== .root
610
+
611
+ Answers operating system root path.
612
+
613
+ [source,ruby]
614
+ ----
615
+ Pathname.root # => Pathname "/"
616
+ ----
617
+
549
618
  ===== #change_dir
550
619
 
551
- Inherits and wraps `Dir.chdir` behavior by changing to directory of current path. See
552
- link:https://rubyapi.org/2.7/o/s?q=Dir.chdir[Dir.chdir] for details.
620
+ Wraps `Dir.chdir` behavior by changing to directory of current path. See
621
+ link:https://rubyapi.org/o/Dir.chdir#method-c-chdir[Dir.chdir] for details.
553
622
 
554
623
  [source,ruby]
555
624
  ----
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.15.1"
8
+ VERSION = "7.16.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -12,6 +12,24 @@ module Refinements
12
12
  end
13
13
  end
14
14
 
15
+ refine Pathname.singleton_class do
16
+ def home
17
+ new ENV["HOME"]
18
+ end
19
+
20
+ def make_temp_dir prefix: "temp-", suffix: nil, root: nil
21
+ Dir.mktmpdir([prefix, suffix], root) { |path| block_given? ? yield(new path) : new(path) }
22
+ end
23
+
24
+ def require_tree root, pattern = "**/*.rb"
25
+ new(root).files(pattern).each { |path| require path.to_s }
26
+ end
27
+
28
+ def root
29
+ new "/"
30
+ end
31
+ end
32
+
15
33
  refine Pathname do
16
34
  def change_dir &block
17
35
  block ? Dir.chdir(self, &block) : (Dir.chdir self and self)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.15.1
4
+ version: 7.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-11-21 00:00:00.000000000 Z
31
+ date: 2020-11-28 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
metadata.gz.sig CHANGED
Binary file