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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.adoc +71 -2
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/pathnames.rb +18 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c7f3818bd1f3d0d3fc39cb4c8721097d5003176b54710888deba6d012b4f77
|
4
|
+
data.tar.gz: f607fea47fce94c11c3ab7dcc6603b169567133fbbe6ca76fb0af0c9fa0196e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da5ff60dc1e6d4055adc850bbe7aa48d02c148f17fb42c9e50f939d577d506097603c2790cf5ce040cce1cb8389e28ebd363d3318d1224d06df4fc6d36e56b3f
|
7
|
+
data.tar.gz: a5a96d51b0e95d1f603262ca8ce767969e3faca18645327f368d8ee03aed7d0fa27211d9e35a8af30bcc6ca86d6dad33d804a4c9f1b830789b39b06dc0791793
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -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
|
-
|
552
|
-
link:https://rubyapi.org/
|
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
|
----
|
data/lib/refinements/identity.rb
CHANGED
@@ -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.
|
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-
|
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
|