refinements 9.3.3 → 9.6.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +87 -0
- data/lib/refinements/arrays.rb +10 -0
- data/lib/refinements/hashes.rb +2 -1
- data/lib/refinements/ios.rb +4 -2
- data/lib/refinements/log_devices.rb +21 -0
- data/lib/refinements/loggers.rb +14 -0
- data/lib/refinements/shared/ios/reread.rb +12 -0
- data/lib/refinements/string_ios.rb +2 -1
- data/lib/refinements.rb +2 -0
- data/refinements.gemspec +2 -1
- data.tar.gz.sig +0 -0
- metadata +7 -3
- 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: 5c0144180dd3a5cabe861b385cd0c766eaf54280ca6812dc6e82db4e564ce6c0
|
4
|
+
data.tar.gz: b339710c168c98fffbe5b1994031f033041c9f6c16b0df96555cb80fd5cd7269
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 926090205f29ac111494e00e7de37b59b8549c6f979c8a0d62d852e9d87193093073ac0f005564243fc472eacf4de68f62bea8b1d45f3f363e113805758f726d
|
7
|
+
data.tar.gz: 22a524d073a48922d6347119f01f4c059bbd2bba8f65a2e6573951b137b772dc3f7797a3596ccb850bb63159a9b2ab501bb334f7ac8a80f66ca93f55886bdb09
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -21,6 +21,8 @@ Enhances the following objects:
|
|
21
21
|
* DateTime
|
22
22
|
* Hash
|
23
23
|
* IO
|
24
|
+
* LogDevice
|
25
|
+
* Logger
|
24
26
|
* Pathname
|
25
27
|
* String
|
26
28
|
* StringIO
|
@@ -73,6 +75,8 @@ require "refinements/strings"
|
|
73
75
|
require "refinements/string_ios"
|
74
76
|
require "refinements/structs"
|
75
77
|
require "refinements/symbols"
|
78
|
+
require "refinements/log_devices"
|
79
|
+
require "refinements/loggers"
|
76
80
|
----
|
77
81
|
|
78
82
|
=== Using
|
@@ -93,6 +97,8 @@ class Example
|
|
93
97
|
using Refinements::StringIOs
|
94
98
|
using Refinements::Structs
|
95
99
|
using Refinements::Symbols
|
100
|
+
using Refinements::LogDevices
|
101
|
+
using Refinements::Loggers
|
96
102
|
end
|
97
103
|
----
|
98
104
|
|
@@ -102,6 +108,24 @@ The following sections demonstrate how each refinement enriches your objects wit
|
|
102
108
|
|
103
109
|
==== Array
|
104
110
|
|
111
|
+
===== #combinatorial?
|
112
|
+
|
113
|
+
Answers if an array is equal to another array when the elements are equal but in any order and/or subset.
|
114
|
+
|
115
|
+
[source,ruby]
|
116
|
+
----
|
117
|
+
example = %w[a b c]
|
118
|
+
|
119
|
+
example.combinatorial? %w[a b c] # true
|
120
|
+
example.combinatorial? %w[c a b] # true
|
121
|
+
example.combinatorial? %w[c] # true
|
122
|
+
example.combinatorial? %w[c b] # true
|
123
|
+
example.combinatorial? %w[x] # false
|
124
|
+
example.combinatorial? %w[z b c] # false
|
125
|
+
example.combinatorial? %w[a b c d] # false
|
126
|
+
example.combinatorial? [] # false
|
127
|
+
----
|
128
|
+
|
105
129
|
===== #compress
|
106
130
|
|
107
131
|
Removes `nil` and empty objects without mutating itself.
|
@@ -254,6 +278,21 @@ example.ring { |(before, current, after)| puts "#{before} #{current} #{after}" }
|
|
254
278
|
# [2 3 1]
|
255
279
|
----
|
256
280
|
|
281
|
+
===== #to_sentence
|
282
|
+
|
283
|
+
Answers a sentence using `", "` as the default delimiter and `"and"` as the default conjunction.
|
284
|
+
Useful when building documentation, answering human readable error messages, etc.
|
285
|
+
|
286
|
+
[source,ruby]
|
287
|
+
----
|
288
|
+
[].to_sentence # ""
|
289
|
+
["test"].to_sentence # "test"
|
290
|
+
["a", :b].to_sentence # "a and b"
|
291
|
+
[1, "a", :b, 2.0, /\w+/].map(&:inspect).to_sentence # 1, "a", :b, 2.0, and /\w+/
|
292
|
+
%w[one two three].to_sentence # "one, two, and three"
|
293
|
+
%w[eins zwei drei].to_sentence delimiter: " ", conjunction: "und" # "eins zwei und drei"
|
294
|
+
----
|
295
|
+
|
257
296
|
==== Big Decimal
|
258
297
|
|
259
298
|
===== #inspect
|
@@ -581,6 +620,54 @@ io.squelch { io.write "Test" } # "#<IO:fd 20>"
|
|
581
620
|
io.reread # ""
|
582
621
|
----
|
583
622
|
|
623
|
+
==== LogDevice
|
624
|
+
|
625
|
+
===== #reread
|
626
|
+
|
627
|
+
Answers previously written content by rewinding to beginning of device.
|
628
|
+
|
629
|
+
[source,ruby]
|
630
|
+
----
|
631
|
+
# With File.
|
632
|
+
device = Logger::LogDevice.new "test.log"
|
633
|
+
device.write "Test."
|
634
|
+
device.reread # "Test."
|
635
|
+
|
636
|
+
# With StringIO.
|
637
|
+
device = Logger::LogDevice.new StringIO.new
|
638
|
+
device.write "Test."
|
639
|
+
device.reread # "Test."
|
640
|
+
|
641
|
+
# With STDOUT.
|
642
|
+
device = Logger::LogDevice.new $stdout
|
643
|
+
device.write "Test."
|
644
|
+
device.reread # ""
|
645
|
+
----
|
646
|
+
|
647
|
+
==== Logger
|
648
|
+
|
649
|
+
===== #reread
|
650
|
+
|
651
|
+
Answers previously written content by rewinding to beginning of log.
|
652
|
+
|
653
|
+
[source,ruby]
|
654
|
+
----
|
655
|
+
# With File.
|
656
|
+
logger = Logger.new "test.log"
|
657
|
+
logger.write "Test."
|
658
|
+
logger.reread # "Test."
|
659
|
+
|
660
|
+
# With StringIO.
|
661
|
+
logger = Logger.new StringIO.new
|
662
|
+
logger.write "Test."
|
663
|
+
logger.reread # "Test."
|
664
|
+
|
665
|
+
# With STDOUT.
|
666
|
+
logger = Logger.new $stdout
|
667
|
+
logger.write "Test."
|
668
|
+
logger.reread # ""
|
669
|
+
----
|
670
|
+
|
584
671
|
==== Pathname
|
585
672
|
|
586
673
|
===== Pathname
|
data/lib/refinements/arrays.rb
CHANGED
@@ -8,6 +8,8 @@ module Refinements
|
|
8
8
|
refine Array do
|
9
9
|
import_methods Shared::Enumerables::Many
|
10
10
|
|
11
|
+
def combinatorial?(other) = !other.empty? && size == union(other).size
|
12
|
+
|
11
13
|
def compress = dup.compress!
|
12
14
|
|
13
15
|
def compress!
|
@@ -32,6 +34,14 @@ module Refinements
|
|
32
34
|
def pad(value, max: size) = dup.fill(value, size..(max - 1))
|
33
35
|
|
34
36
|
def ring(&) = [last, *self, first].each_cons(3, &)
|
37
|
+
|
38
|
+
def to_sentence delimiter: ", ", conjunction: "and"
|
39
|
+
case length
|
40
|
+
when (3..) then "#{self[..-2].join delimiter}#{delimiter}#{conjunction} #{last}"
|
41
|
+
when 2 then join " #{conjunction} "
|
42
|
+
else join
|
43
|
+
end
|
44
|
+
end
|
35
45
|
end
|
36
46
|
end
|
37
47
|
end
|
data/lib/refinements/hashes.rb
CHANGED
@@ -21,7 +21,8 @@ module Refinements
|
|
21
21
|
def compress!
|
22
22
|
return self if empty?
|
23
23
|
|
24
|
-
compact
|
24
|
+
compact!
|
25
|
+
delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
|
25
26
|
end
|
26
27
|
|
27
28
|
def deep_merge other
|
data/lib/refinements/ios.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "refinements/shared/ios/reread"
|
4
|
+
|
3
5
|
module Refinements
|
4
6
|
# Provides additional enhancements to the IO primitive.
|
5
7
|
module IOs
|
@@ -15,6 +17,8 @@ module Refinements
|
|
15
17
|
end
|
16
18
|
|
17
19
|
refine IO do
|
20
|
+
import_methods Shared::IOs::Reread
|
21
|
+
|
18
22
|
def redirect other
|
19
23
|
return self unless block_given?
|
20
24
|
|
@@ -24,8 +28,6 @@ module Refinements
|
|
24
28
|
reopen backup
|
25
29
|
end
|
26
30
|
|
27
|
-
def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
|
28
|
-
|
29
31
|
def squelch(&) = self.class.void.then { |void| redirect(void, &) }
|
30
32
|
end
|
31
33
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "refinements/string_ios"
|
5
|
+
|
6
|
+
module Refinements
|
7
|
+
# Provides additional enhancements to a log device.
|
8
|
+
module LogDevices
|
9
|
+
using StringIOs
|
10
|
+
|
11
|
+
refine Logger::LogDevice do
|
12
|
+
def reread
|
13
|
+
case dev
|
14
|
+
when File then dev.class.new(dev).read
|
15
|
+
when StringIO then dev.reread
|
16
|
+
else ""
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Refinements
|
4
|
+
module Shared
|
5
|
+
module IOs
|
6
|
+
# Provides shared functionality for I/O object rewinding.
|
7
|
+
module Reread
|
8
|
+
def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "stringio"
|
4
|
+
require "refinements/shared/ios/reread"
|
4
5
|
|
5
6
|
module Refinements
|
6
7
|
# Provides additional enhancements to the StringIO primitive.
|
7
8
|
module StringIOs
|
8
9
|
refine StringIO do
|
9
|
-
|
10
|
+
import_methods Shared::IOs::Reread
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
data/lib/refinements.rb
CHANGED
data/refinements.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "refinements"
|
5
|
-
spec.version = "9.
|
5
|
+
spec.version = "9.6.0"
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
8
8
|
spec.homepage = "https://www.alchemists.io/projects/refinements"
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
"bug_tracker_uri" => "https://github.com/bkuhlmann/refinements/issues",
|
14
14
|
"changelog_uri" => "https://www.alchemists.io/projects/refinements/versions",
|
15
15
|
"documentation_uri" => "https://www.alchemists.io/projects/refinements",
|
16
|
+
"funding_uri" => "https://github.com/sponsors/bkuhlmann",
|
16
17
|
"label" => "Refinements",
|
17
18
|
"rubygems_mfa_required" => "true",
|
18
19
|
"source_code_uri" => "https://github.com/bkuhlmann/refinements"
|
data.tar.gz.sig
CHANGED
Binary file
|
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: 9.
|
4
|
+
version: 9.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -28,7 +28,7 @@ cert_chain:
|
|
28
28
|
CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
|
29
29
|
RFE=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2022-
|
31
|
+
date: 2022-07-17 00:00:00.000000000 Z
|
32
32
|
dependencies: []
|
33
33
|
description:
|
34
34
|
email:
|
@@ -47,8 +47,11 @@ files:
|
|
47
47
|
- lib/refinements/date_times.rb
|
48
48
|
- lib/refinements/hashes.rb
|
49
49
|
- lib/refinements/ios.rb
|
50
|
+
- lib/refinements/log_devices.rb
|
51
|
+
- lib/refinements/loggers.rb
|
50
52
|
- lib/refinements/pathnames.rb
|
51
53
|
- lib/refinements/shared/enumerables/many.rb
|
54
|
+
- lib/refinements/shared/ios/reread.rb
|
52
55
|
- lib/refinements/string_ios.rb
|
53
56
|
- lib/refinements/strings.rb
|
54
57
|
- lib/refinements/structs.rb
|
@@ -61,6 +64,7 @@ metadata:
|
|
61
64
|
bug_tracker_uri: https://github.com/bkuhlmann/refinements/issues
|
62
65
|
changelog_uri: https://www.alchemists.io/projects/refinements/versions
|
63
66
|
documentation_uri: https://www.alchemists.io/projects/refinements
|
67
|
+
funding_uri: https://github.com/sponsors/bkuhlmann
|
64
68
|
label: Refinements
|
65
69
|
rubygems_mfa_required: 'true'
|
66
70
|
source_code_uri: https://github.com/bkuhlmann/refinements
|
@@ -79,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
83
|
- !ruby/object:Gem::Version
|
80
84
|
version: '0'
|
81
85
|
requirements: []
|
82
|
-
rubygems_version: 3.3.
|
86
|
+
rubygems_version: 3.3.18
|
83
87
|
signing_key:
|
84
88
|
specification_version: 4
|
85
89
|
summary: A collection of refinements to core Ruby objects.
|
metadata.gz.sig
CHANGED
Binary file
|