refinements 9.8.0 → 10.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +23 -61
- data/lib/refinements/arrays.rb +2 -2
- data/lib/refinements/hashes.rb +9 -22
- data/lib/refinements/string_ios.rb +1 -1
- data/lib/refinements/structs.rb +0 -7
- data/lib/refinements.rb +3 -3
- data/refinements.gemspec +2 -2
- data.tar.gz.sig +0 -0
- metadata +4 -4
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6886f2e81d621658654c24748db65834f2f0d6a1f37b9cd6f5f201dedc0d23e6
|
4
|
+
data.tar.gz: c047e00e34e10f9c4ed31561c5e64e4d247151dec65b1251a14f79d273e21d02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 771838c7e7fa1b044b861724ec99ab78a2f1393db0dc9f2906ebf9fd58d34aa2adee55dccf7c4cd045e9ac4b3b30a49fbc613b23628ca216ce47c271289038d4
|
7
|
+
data.tar.gz: 13c855b9fdc681ab75e008a61059bec785f8918f7fbfa44576100a5f014102ea806d6b0061eae89475106cb8cc55625026c536d5f6d55144d8cf06127604d7cb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -128,28 +128,32 @@ example.combinatorial? [] # false
|
|
128
128
|
|
129
129
|
===== #compress
|
130
130
|
|
131
|
-
Removes `nil` and empty objects without mutating itself.
|
131
|
+
Removes `nil` and empty objects without mutating itself. Answers itself if there is nothing to remove.
|
132
132
|
|
133
133
|
[source,ruby]
|
134
134
|
----
|
135
135
|
object = Object.new
|
136
136
|
example = [1, "blueberry", nil, "", [], {}, object]
|
137
137
|
|
138
|
+
[].compress # []
|
139
|
+
[1, 2].compress # [1, 2]
|
138
140
|
example.compress # [1, "blueberry", object]
|
139
141
|
example # [1, "blueberry", nil, "", [], {}, object]
|
140
142
|
----
|
141
143
|
|
142
144
|
===== #compress!
|
143
145
|
|
144
|
-
Removes `nil` and empty values while mutating itself.
|
146
|
+
Removes `nil` and empty values while mutating itself. Answers `nil` if there is nothing to remove.
|
145
147
|
|
146
148
|
[source,ruby]
|
147
149
|
----
|
148
150
|
object = Object.new
|
149
151
|
example = [1, "blueberry", nil, "", [], {}, object]
|
150
152
|
|
151
|
-
|
152
|
-
|
153
|
+
[].compress! # nil
|
154
|
+
[1, 2].compress! # nil
|
155
|
+
example.compress! # [1, "blueberry", object]
|
156
|
+
example # [1, "blueberry", object]
|
153
157
|
----
|
154
158
|
|
155
159
|
===== #excluding
|
@@ -219,7 +223,7 @@ Answers the maximum extracted value from a collection of objects.
|
|
219
223
|
|
220
224
|
[source,ruby]
|
221
225
|
----
|
222
|
-
Point = Struct.new :x, :y
|
226
|
+
Point = Struct.new :x, :y
|
223
227
|
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
|
224
228
|
|
225
229
|
points.maximum(:x) # 2
|
@@ -244,7 +248,7 @@ Answers the minimum extracted value from a collection of objects.
|
|
244
248
|
|
245
249
|
[source,ruby]
|
246
250
|
----
|
247
|
-
Point = Struct.new :x, :y
|
251
|
+
Point = Struct.new :x, :y
|
248
252
|
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
|
249
253
|
|
250
254
|
points.minimum(:x) # 0
|
@@ -367,28 +371,32 @@ example[:b] # []
|
|
367
371
|
|
368
372
|
===== #compress
|
369
373
|
|
370
|
-
Removes `nil` and empty objects without mutating itself.
|
374
|
+
Removes `nil` and empty objects without mutating itself. Answers itself if there is nothing to remove.
|
371
375
|
|
372
376
|
[source,ruby]
|
373
377
|
----
|
374
378
|
object = Object.new
|
375
379
|
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
376
380
|
|
377
|
-
|
378
|
-
|
381
|
+
{}.compress # {}
|
382
|
+
{a: 1, b: 2}.compress # {a: 1, b: 2}
|
383
|
+
example.compress # {a: 1, b: "blueberry", g: object}
|
384
|
+
example # {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
379
385
|
----
|
380
386
|
|
381
387
|
===== #compress!
|
382
388
|
|
383
|
-
Removes `nil` and empty objects while mutating itself.
|
389
|
+
Removes `nil` and empty objects while mutating itself. Answers `nil` if there is nothing to remove.
|
384
390
|
|
385
391
|
[source,ruby]
|
386
392
|
----
|
387
393
|
object = Object.new
|
388
394
|
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
389
395
|
|
390
|
-
|
391
|
-
|
396
|
+
{}.compress! # nil
|
397
|
+
{a: 1, b: 2}.compress! # nil
|
398
|
+
example.compress! # {a: 1, b: "blueberry", g: object}
|
399
|
+
example # {a: 1, b: "blueberry", g: object}
|
392
400
|
----
|
393
401
|
|
394
402
|
===== #deep_merge
|
@@ -485,9 +493,6 @@ though.
|
|
485
493
|
{a: {b: 1}}.flatten_keys prefix: :test # {test_a_b: 1}
|
486
494
|
{a: {b: 1}}.flatten_keys delimiter: :| # {:"a|b" => 1}
|
487
495
|
|
488
|
-
{a: {b: 1}}.flatten_keys cast: :to_s # {"a_b" => 1}
|
489
|
-
{"a" => {"b" => 1}}.flatten_keys cast: :to_sym # {a_b: 1}
|
490
|
-
|
491
496
|
example = {a: {b: 1}}
|
492
497
|
example.flatten_keys # {a_b: 1}
|
493
498
|
example # {a: {b: 1}}
|
@@ -500,6 +505,9 @@ though.
|
|
500
505
|
|
501
506
|
[source,ruby]
|
502
507
|
----
|
508
|
+
{a: {b: 1}}.flatten_keys! prefix: :test # {test_a_b: 1}
|
509
|
+
{a: {b: 1}}.flatten_keys! delimiter: :| # {:"a|b" => 1}
|
510
|
+
|
503
511
|
example = {a: {b: 1}}
|
504
512
|
example.flatten_keys! # {a_b: 1}
|
505
513
|
example # {a_b: 1}
|
@@ -597,14 +605,6 @@ example.transform_with bogus: -> value { value.tr "<>", "" }
|
|
597
605
|
# {email: "<jd@example.com>"}
|
598
606
|
----
|
599
607
|
|
600
|
-
Nil values are skipped:
|
601
|
-
|
602
|
-
[source,ruby]
|
603
|
-
----
|
604
|
-
{email: nil}.transform_with email: -> value { value.tr "<>", "" }
|
605
|
-
# {email: nil}
|
606
|
-
----
|
607
|
-
|
608
608
|
The original object will not be mutated:
|
609
609
|
|
610
610
|
[source,ruby]
|
@@ -635,14 +635,6 @@ example.transform_with! bogus: -> value { value.tr "<>", "" }
|
|
635
635
|
# {email: "<jd@example.com>"}
|
636
636
|
----
|
637
637
|
|
638
|
-
Nil values are skipped:
|
639
|
-
|
640
|
-
[source,ruby]
|
641
|
-
----
|
642
|
-
{email: nil}.transform_with! email: -> value { value.tr "<>", "" }
|
643
|
-
# {email: nil}
|
644
|
-
----
|
645
|
-
|
646
638
|
The original object will be mutated:
|
647
639
|
|
648
640
|
[source,ruby]
|
@@ -1273,36 +1265,6 @@ buffer # "This is a test."
|
|
1273
1265
|
|
1274
1266
|
==== Struct
|
1275
1267
|
|
1276
|
-
===== .keyworded?
|
1277
|
-
|
1278
|
-
⚠️ Will be removed in the next major version. Use `.keyword_init?` instead.
|
1279
|
-
|
1280
|
-
Answers whether a struct was constructed with keyword or positional arguments.
|
1281
|
-
|
1282
|
-
[source,ruby]
|
1283
|
-
----
|
1284
|
-
Struct.new(:a, keyword_init: true).keyworded? # true
|
1285
|
-
Struct.new(:a).keyworded? # false
|
1286
|
-
----
|
1287
|
-
|
1288
|
-
===== .with_keywords
|
1289
|
-
|
1290
|
-
Answers a struct instance with given keyword arguments regardless of
|
1291
|
-
whether the struct was constructed with positional or keyword arguments.
|
1292
|
-
|
1293
|
-
[source,ruby]
|
1294
|
-
----
|
1295
|
-
Example = Struct.new :a, :b, :c
|
1296
|
-
Example.with_keywords a: 1, b: 2, c: 3 # #<struct a=1, b=2, c=3>
|
1297
|
-
Example.with_keywords a: 1 # #<struct a=1, b=nil, c=nil>
|
1298
|
-
Example.with_keywords c: 1 # #<struct a=nil, b=nil, c=1>
|
1299
|
-
|
1300
|
-
Example = Struct.new :a, :b, :c, keyword_init: true
|
1301
|
-
Example.with_keywords a: 1, b: 2, c: 3 # #<struct a=1, b=2, c=3>
|
1302
|
-
Example.with_keywords a: 1 # #<struct a=1, b=nil, c=nil>
|
1303
|
-
Example.with_keywords c: 1 # #<struct a=nil, b=nil, c=1>
|
1304
|
-
----
|
1305
|
-
|
1306
1268
|
===== .with_positions
|
1307
1269
|
|
1308
1270
|
Answers a struct instance with given positional arguments regardless of
|
data/lib/refinements/arrays.rb
CHANGED
@@ -10,11 +10,11 @@ module Refinements
|
|
10
10
|
|
11
11
|
def combinatorial?(other) = !other.empty? && size == union(other).size
|
12
12
|
|
13
|
-
def compress =
|
13
|
+
def compress = compact.delete_if { |element| element.respond_to?(:empty?) && element.empty? }
|
14
14
|
|
15
15
|
def compress!
|
16
|
-
compact!
|
17
16
|
delete_if { |element| element.respond_to?(:empty?) && element.empty? }
|
17
|
+
compact!
|
18
18
|
end
|
19
19
|
|
20
20
|
def excluding(*elements) = self - elements.flatten
|
data/lib/refinements/hashes.rb
CHANGED
@@ -16,13 +16,11 @@ module Refinements
|
|
16
16
|
refine Hash do
|
17
17
|
import_methods Shared::Enumerables::Many
|
18
18
|
|
19
|
-
def compress =
|
19
|
+
def compress = compact.delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
|
20
20
|
|
21
21
|
def compress!
|
22
|
-
return self if empty?
|
23
|
-
|
24
|
-
compact!
|
25
22
|
delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
|
23
|
+
compact!
|
26
24
|
end
|
27
25
|
|
28
26
|
def deep_merge other
|
@@ -49,24 +47,17 @@ module Refinements
|
|
49
47
|
|
50
48
|
def fetch_value(key, *default_value, &) = fetch(key, *default_value, &) || default_value.first
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
reduce({}) do |flat, (key, value)|
|
57
|
-
flat_key = prefix ? "#{prefix}#{delimiter}#{key}" : key
|
50
|
+
def flatten_keys prefix: nil, delimiter: "_"
|
51
|
+
reduce({}) do |accumulator, (key, value)|
|
52
|
+
flat_key = prefix ? "#{prefix}#{delimiter}#{key}".to_sym : key
|
58
53
|
|
59
|
-
next
|
54
|
+
next accumulator.merge flat_key => value unless value in Hash
|
60
55
|
|
61
|
-
|
62
|
-
recurse { value.flatten_keys prefix: flat_key, delimiter:, cast: }
|
63
|
-
)
|
56
|
+
accumulator.merge(recurse { value.flatten_keys prefix: flat_key, delimiter: })
|
64
57
|
end
|
65
58
|
end
|
66
59
|
|
67
|
-
def flatten_keys!
|
68
|
-
replace flatten_keys(prefix:, delimiter:, cast:)
|
69
|
-
end
|
60
|
+
def flatten_keys!(prefix: nil, delimiter: "_") = replace flatten_keys(prefix:, delimiter:)
|
70
61
|
|
71
62
|
def recurse &block
|
72
63
|
return self unless block
|
@@ -86,11 +77,7 @@ module Refinements
|
|
86
77
|
def transform_with(operations) = dup.transform_with! operations
|
87
78
|
|
88
79
|
def transform_with! operations
|
89
|
-
operations.each
|
90
|
-
value = self[key]
|
91
|
-
self[key] = function.call value if value
|
92
|
-
end
|
93
|
-
|
80
|
+
operations.each { |key, function| self[key] = function.call self[key] if key? key }
|
94
81
|
self
|
95
82
|
end
|
96
83
|
|
data/lib/refinements/structs.rb
CHANGED
@@ -4,13 +4,6 @@ module Refinements
|
|
4
4
|
# Provides additional enhancements to the Struct primitive.
|
5
5
|
module Structs
|
6
6
|
refine Struct.singleton_class do
|
7
|
-
def keyworded?
|
8
|
-
warn "[DEPRECATION]: .keyworded? is deprecated, use .keyword_init? instead."
|
9
|
-
inspect.include? "keyword_init: true"
|
10
|
-
end
|
11
|
-
|
12
|
-
def with_keywords(**arguments) = keyword_init? ? new(**arguments) : new.merge!(**arguments)
|
13
|
-
|
14
7
|
def with_positions(*values) = keyword_init? ? new(**members.zip(values).to_h) : new(*values)
|
15
8
|
end
|
16
9
|
|
data/lib/refinements.rb
CHANGED
@@ -5,10 +5,10 @@ require "refinements/big_decimals"
|
|
5
5
|
require "refinements/date_times"
|
6
6
|
require "refinements/hashes"
|
7
7
|
require "refinements/ios"
|
8
|
+
require "refinements/log_devices"
|
9
|
+
require "refinements/loggers"
|
8
10
|
require "refinements/pathnames"
|
9
|
-
require "refinements/strings"
|
10
11
|
require "refinements/string_ios"
|
12
|
+
require "refinements/strings"
|
11
13
|
require "refinements/structs"
|
12
14
|
require "refinements/symbols"
|
13
|
-
require "refinements/log_devices"
|
14
|
-
require "refinements/loggers"
|
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 = "
|
5
|
+
spec.version = "10.0.0"
|
6
6
|
spec.authors = ["Brooke Kuhlmann"]
|
7
7
|
spec.email = ["brooke@alchemists.io"]
|
8
8
|
spec.homepage = "https://www.alchemists.io/projects/refinements"
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.signing_key = Gem.default_key_path
|
23
23
|
spec.cert_chain = [Gem.default_cert_path]
|
24
24
|
|
25
|
-
spec.required_ruby_version = "~> 3.
|
25
|
+
spec.required_ruby_version = "~> 3.2"
|
26
26
|
|
27
27
|
spec.files = Dir["*.gemspec", "lib/**/*"]
|
28
28
|
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
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:
|
4
|
+
version: 10.0.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-12-25 00:00:00.000000000 Z
|
32
32
|
dependencies: []
|
33
33
|
description:
|
34
34
|
email:
|
@@ -76,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
76
|
requirements:
|
77
77
|
- - "~>"
|
78
78
|
- !ruby/object:Gem::Version
|
79
|
-
version: '3.
|
79
|
+
version: '3.2'
|
80
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - ">="
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.3.
|
86
|
+
rubygems_version: 3.3.26
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: A collection of refinements to core Ruby objects.
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
��"g��2����͆knM�x����FT��N��(@j����d?����Z���/�|19����h�WCޖ���Xn��KgB���QE������`a�U��j���Qx���i���}��;dS�����^6�;n����t����gcX��c ��ꭌ�1g1�h�I�z�/�C/vEL��FR��#XxYl�4��W�)�ɽ�*�-x�O2�&��X%�F�$����r����\��z��v�#J��n
|
1
|
+
:vqw��,�}�p���C�V3Z������w�����̇�����B@�-族�fS���c��S�7$b\g�x�Ɂ��WS%�[��M��!�.�C��;8��w�|%u[�/��t���ƌg�H�v��#f�&�����M1�4Y���9݁�5H_�-��W[̈́B� �D���������!��с�g��H�v���^Ʊ�-�OOv����<�$��'`�6M�9�r���7���$�����ׇC@{I��|[>ӥ��
|