refinements 12.8.0 → 12.9.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 +51 -7
- data/lib/refinements/array.rb +1 -1
- data/lib/refinements/hash.rb +8 -2
- data/lib/refinements/pathname.rb +2 -2
- data/refinements.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -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: 229ada32a4378800013462184db88be59d33109cbbd63c8c6378add52fc7b321
|
4
|
+
data.tar.gz: 4f0291390f858b45e2066dc9eac5e3f06ceef5c9e1051160aa7c625e734c78c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbe61e5483ff24ffe0d9852e3f1c34e613f53a48f8a96cb15b862bf2528c448df71e9357d2910068b7e41275a916a9169f99e6b5b67c355df73eaf3e6ac2d124
|
7
|
+
data.tar.gz: 3f77b617a157b3d9be6735a08a9340ddd945642107d5e2728e384f6496197a44e180cfcce8c5738ec5ea509df883fcc5ca3b1261ffaddeaedbcfe0764987d9d0
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -635,7 +635,7 @@ Any object that _is not_ the same type will have a `nil` value as shown in the l
|
|
635
635
|
|
636
636
|
Fetches value for exiting or missing key. Behavior is identical to `#fetch` except when the value of
|
637
637
|
the key is `nil` you'll get the default value instead. This eliminates the need for using an _or_
|
638
|
-
expression `example.fetch(:desired_key) || "default_value"`.
|
638
|
+
expression: `example.fetch(:desired_key) || "default_value"`.
|
639
639
|
|
640
640
|
[source,ruby]
|
641
641
|
----
|
@@ -650,8 +650,7 @@ expression `example.fetch(:desired_key) || "default_value"`.
|
|
650
650
|
|
651
651
|
===== #flatten_keys
|
652
652
|
|
653
|
-
Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays
|
654
|
-
though.
|
653
|
+
Flattens nested keys as top-level keys without mutating itself. Keys are converted to symbols. Does not handle nested arrays.
|
655
654
|
|
656
655
|
[source,ruby]
|
657
656
|
----
|
@@ -665,8 +664,7 @@ example # {a: {b: 1}}
|
|
665
664
|
|
666
665
|
===== #flatten_keys!
|
667
666
|
|
668
|
-
Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays
|
669
|
-
though.
|
667
|
+
Flattens nested keys as top-level keys while mutating itself. Keys are converted to symbols. Does not handle nested arrays.
|
670
668
|
|
671
669
|
[source,ruby]
|
672
670
|
----
|
@@ -747,6 +745,52 @@ example.symbolize_keys! # {a: 1, b: 2}
|
|
747
745
|
example # {a: 1, b: 2}
|
748
746
|
----
|
749
747
|
|
748
|
+
===== #transform_value
|
749
|
+
|
750
|
+
Transforms a value for the specified key _only_ if the key exists and a block is given. Otherwise, the original hash is answered. Does not mutate itself.
|
751
|
+
|
752
|
+
[source,ruby]
|
753
|
+
----
|
754
|
+
example = {a: 1, b: 2}
|
755
|
+
|
756
|
+
example.transform_value :b # {a: 1, b: 2}
|
757
|
+
example.transform_value(:b) { 20 } # {a: 1, b: 20}
|
758
|
+
example.transform_value(:b) { |value| value * 10 } # {a: 1, b: 20}
|
759
|
+
example.transform_value :c # {a: 1, b: 2}
|
760
|
+
example.transform_value(:c) { :bogus } # {a: 1, b: 2}
|
761
|
+
----
|
762
|
+
|
763
|
+
The original object _is not_ mutated:
|
764
|
+
|
765
|
+
[source,ruby]
|
766
|
+
----
|
767
|
+
example.transform_value(:b) { 20 } # {a: 1, b: 20}
|
768
|
+
example # {a: 1, b: 2}
|
769
|
+
----
|
770
|
+
|
771
|
+
===== #transform_value!
|
772
|
+
|
773
|
+
Transforms a value for the specified key _only_ if the key exists and a block is given. Otherwise, the original hash is answered. Mutates itself.
|
774
|
+
|
775
|
+
[source,ruby]
|
776
|
+
----
|
777
|
+
example = {a: 1, b: 2}
|
778
|
+
|
779
|
+
example.transform_value! :b # {a: 1, b: 2}
|
780
|
+
example.transform_value!(:b) { 20 } # {a: 1, b: 20}
|
781
|
+
example.transform_value!(:b) { |value| value * 10 } # {a: 1, b: 20}
|
782
|
+
example.transform_value! :c # {a: 1, b: 2}
|
783
|
+
example.transform_value!(:c) { :bogus } # {a: 1, b: 2}
|
784
|
+
----
|
785
|
+
|
786
|
+
The original object _is_ mutated:
|
787
|
+
|
788
|
+
[source,ruby]
|
789
|
+
----
|
790
|
+
example.transform_value!(:b) { 20 } # {a: 1, b: 20}
|
791
|
+
example # {a: 1, b: 20}
|
792
|
+
----
|
793
|
+
|
750
794
|
===== #transform_with
|
751
795
|
|
752
796
|
Transforms values of keys using specific operations (i.e. any object that responds to `#call`). Does not mutate itself and you can transform multiple values at once:
|
@@ -768,7 +812,7 @@ example.transform_with bogus: -> value { value.tr "<>", "" }
|
|
768
812
|
# {email: "<jd@example.com>"}
|
769
813
|
----
|
770
814
|
|
771
|
-
The original object
|
815
|
+
The original object _is not_ mutated:
|
772
816
|
|
773
817
|
[source,ruby]
|
774
818
|
----
|
@@ -796,7 +840,7 @@ example.transform_with! bogus: -> value { value.tr "<>", "" }
|
|
796
840
|
# {email: "<jd@example.com>"}
|
797
841
|
----
|
798
842
|
|
799
|
-
The original object
|
843
|
+
The original object _is_ mutated:
|
800
844
|
|
801
845
|
[source,ruby]
|
802
846
|
----
|
data/lib/refinements/array.rb
CHANGED
@@ -19,7 +19,7 @@ module Refinements
|
|
19
19
|
|
20
20
|
def excluding(*elements) = self - elements.flatten
|
21
21
|
|
22
|
-
def filter_find(&
|
22
|
+
def filter_find(&) = block_given? ? lazy.map(&).find(&:itself) : lazy
|
23
23
|
|
24
24
|
def including(*elements) = self + elements.flatten
|
25
25
|
|
data/lib/refinements/hash.rb
CHANGED
@@ -80,9 +80,15 @@ module Refinements
|
|
80
80
|
|
81
81
|
def symbolize_keys! = transform_keys!(&:to_sym)
|
82
82
|
|
83
|
-
def
|
83
|
+
def transform_value(key, &) = dup.transform_value!(key, &)
|
84
84
|
|
85
|
-
def
|
85
|
+
def transform_value! key
|
86
|
+
block_given? && key?(key) ? merge!(key => yield(self[key])) : self
|
87
|
+
end
|
88
|
+
|
89
|
+
def transform_with(**) = dup.transform_with!(**)
|
90
|
+
|
91
|
+
def transform_with!(**operations)
|
86
92
|
operations.each { |key, function| self[key] = function.call self[key] if key? key }
|
87
93
|
self
|
88
94
|
end
|
data/lib/refinements/pathname.rb
CHANGED
@@ -53,14 +53,14 @@ module Refinements
|
|
53
53
|
def delete_suffix(pattern) = parent.join %(#{name.sub(/#{pattern}\z/, "")}#{extname})
|
54
54
|
|
55
55
|
def directories pattern = "*", flag: File::FNM_SYSCASE
|
56
|
-
glob(pattern, flag).select(&:directory?)
|
56
|
+
glob(pattern, flag).select(&:directory?)
|
57
57
|
end
|
58
58
|
|
59
59
|
def empty = file? ? (truncate(0) and self) : remove_tree.make_dir
|
60
60
|
|
61
61
|
def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
|
62
62
|
|
63
|
-
def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?)
|
63
|
+
def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?)
|
64
64
|
|
65
65
|
def gsub(pattern, replacement) = self.class.new(to_s.gsub(pattern, replacement))
|
66
66
|
|
data/refinements.gemspec
CHANGED
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: 12.
|
4
|
+
version: 12.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
|
36
36
|
gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2024-
|
38
|
+
date: 2024-10-01 00:00:00.000000000 Z
|
39
39
|
dependencies: []
|
40
40
|
description:
|
41
41
|
email:
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
|
-
rubygems_version: 3.5.
|
99
|
+
rubygems_version: 3.5.20
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: A collection of core object refinements.
|
metadata.gz.sig
CHANGED
Binary file
|