refinements 7.18.0 → 8.2.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 +1 -2
- data.tar.gz.sig +2 -1
- data/README.adoc +45 -83
- data/lib/refinements.rb +0 -1
- data/lib/refinements/arrays.rb +21 -41
- data/lib/refinements/big_decimals.rb +1 -3
- data/lib/refinements/date_times.rb +1 -3
- data/lib/refinements/hashes.rb +10 -58
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/ios.rb +2 -6
- data/lib/refinements/pathnames.rb +12 -41
- data/lib/refinements/string_ios.rb +1 -3
- data/lib/refinements/strings.rb +3 -14
- data/lib/refinements/structs.rb +6 -16
- metadata +14 -15
- metadata.gz.sig +0 -0
- data/lib/refinements/files.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5706b329caaea4cbf42c9dd34d8da325d5e4b5628385a760de2ca4b4c5efaf06
|
4
|
+
data.tar.gz: c20a4aad691df3a683d3ea29d58ae0dbcef4475d297460a945874c2298972864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d14f810b454fe4e3116dc35b04a3701485b9ddad99889db58da96cec8e8556271ec53292447861748909add9d293a21a7c3c7a49fc16720fd61f7654dc2251a4
|
7
|
+
data.tar.gz: 61defc07d39c9de58db72ae0f937319694d156c6a0ed2896f6c2a9b645bfbb5fd829e01e96c242764cb4115dc030dbb5ffcb8010446cec34316b7666b62f8061
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
F��
|
2
|
-
UJ=Ue����yA��a��]�3v�� �Ww��_3�:B\������rf�����<�p�hKO����:�Or#�G��LX���G�o���#����F
|
1
|
+
�_1�̰0�$%���!���&�=F���Kmn�%s���0(\]���x-��8yXx��O0����6k=�p��b}��7�E��vvԝ:F�]���2�s��}mQ� �T�1�4���~:�M�ի���ɋ�� ӏќ�7�Wd"о-D���料�Fꌞ�&�*_/��L`"bEY^�k�{"���6f��(�� �9g,�Y5����74���gr��I�?j�]�'@4=�S{(��&�ڳ�#�iփ��|���T
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
���*�l�(�30`�l�c��ړǑQ�;��M7|����Kr��y�d��$�bϸ�I��3=HF:O<�ܠ�M���$%���1��w�rU��@�n۩/l$n��@R(�N�gy�#T�Ǹ�.�����^�����Lܐ�*� �Y��j,�����?�
|
2
|
+
�_�-Y�ȷT�L`��eE�jd䤽��v�b��>F5K�c�RvE)>�҃��0�.YM�%����qb��� �IA����?���=ƥ�k�R��t�$�
|
data/README.adoc
CHANGED
@@ -22,7 +22,6 @@ Enhances the following objects:
|
|
22
22
|
* Array
|
23
23
|
* BigDecimal
|
24
24
|
* DateTime
|
25
|
-
* File
|
26
25
|
* Hash
|
27
26
|
* IO
|
28
27
|
* Pathname
|
@@ -70,7 +69,6 @@ gem "refinements", require: false
|
|
70
69
|
require "refinements/arrays"
|
71
70
|
require "refinements/big_decimals"
|
72
71
|
require "refinements/date_times"
|
73
|
-
require "refinements/files"
|
74
72
|
require "refinements/hashes"
|
75
73
|
require "refinements/ios"
|
76
74
|
require "refinements/pathnames"
|
@@ -90,7 +88,6 @@ class Example
|
|
90
88
|
using Refinements::Arrays
|
91
89
|
using Refinements::BigDecimals
|
92
90
|
using Refinements::DateTimes
|
93
|
-
using Refinements::Files
|
94
91
|
using Refinements::Hashes
|
95
92
|
using Refinements::IOs
|
96
93
|
using Refinements::Pathnames
|
@@ -138,6 +135,23 @@ Removes given array or elements without mutating itself.
|
|
138
135
|
[1, 2, 3, 4, 5].excluding 4, 5 # => [1, 2, 3]
|
139
136
|
----
|
140
137
|
|
138
|
+
===== #filter_find
|
139
|
+
|
140
|
+
Answers the first truthy and filtered result from a collection.
|
141
|
+
|
142
|
+
[source,ruby]
|
143
|
+
----
|
144
|
+
handlers = [
|
145
|
+
->(object) { object if object == :b },
|
146
|
+
proc { false },
|
147
|
+
->(object) { object if object == :a }
|
148
|
+
]
|
149
|
+
|
150
|
+
handlers.filter_find # => Enumerator::Lazy
|
151
|
+
handlers.filter_find { |handler| handler.call :a } # => :a
|
152
|
+
handlers.filter_find { |handler| handler.call :x } # => nil
|
153
|
+
----
|
154
|
+
|
141
155
|
===== #including
|
142
156
|
|
143
157
|
Adds given array or elements without mutating itself.
|
@@ -159,6 +173,19 @@ Inserts additional elements or array between all members of given array.
|
|
159
173
|
[1, 2, 3].intersperse %i[a b c] # => [1, :a, :b, :c, 2, :a, :b, :c, 3]
|
160
174
|
----
|
161
175
|
|
176
|
+
===== #maximum
|
177
|
+
|
178
|
+
Answers the maximum extracted value from a collection of objects.
|
179
|
+
|
180
|
+
[source,ruby]
|
181
|
+
----
|
182
|
+
Point = Struct.new :x, :y, keyword_init: true
|
183
|
+
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
|
184
|
+
|
185
|
+
points.maximum(:x) # => 2
|
186
|
+
points.maximum(:y) # => 3
|
187
|
+
----
|
188
|
+
|
162
189
|
===== #mean
|
163
190
|
|
164
191
|
Answers mean/average all elements within an array.
|
@@ -171,6 +198,19 @@ Answers mean/average all elements within an array.
|
|
171
198
|
[1.25, 1.5, 1.75].mean # => 1.5
|
172
199
|
----
|
173
200
|
|
201
|
+
===== #minimum
|
202
|
+
|
203
|
+
Answers the minimum extracted value from a collection of objects.
|
204
|
+
|
205
|
+
[source,ruby]
|
206
|
+
----
|
207
|
+
Point = Struct.new :x, :y, keyword_init: true
|
208
|
+
points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
|
209
|
+
|
210
|
+
points.minimum(:x) # => 0
|
211
|
+
points.minimum(:y) # => 1
|
212
|
+
----
|
213
|
+
|
174
214
|
===== #pad
|
175
215
|
|
176
216
|
Answers new array padded with given value up to a maximum size. Useful in situations where an array
|
@@ -220,18 +260,6 @@ Answers new DateTime object for current UTC date/time.
|
|
220
260
|
DateTime.utc # => #<DateTime: 2019-12-31T18:17:00+00:00 ((2458849j,65820s,181867000n),+0s,2299161j)>
|
221
261
|
----
|
222
262
|
|
223
|
-
==== File
|
224
|
-
|
225
|
-
===== .rewrite
|
226
|
-
|
227
|
-
When given a file path and a block, it provides the contents of the recently read file for
|
228
|
-
manipulation and immediate writing back to the same file.
|
229
|
-
|
230
|
-
[source,ruby]
|
231
|
-
----
|
232
|
-
File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
|
233
|
-
----
|
234
|
-
|
235
263
|
==== Hash
|
236
264
|
|
237
265
|
===== .infinite
|
@@ -324,28 +352,6 @@ example.deep_symbolize_keys! # => {a: {b: 1}}
|
|
324
352
|
example # => {a: {b: 1}}
|
325
353
|
----
|
326
354
|
|
327
|
-
===== #except
|
328
|
-
|
329
|
-
Answers new hash with given keys removed without mutating itself.
|
330
|
-
|
331
|
-
[source,ruby]
|
332
|
-
----
|
333
|
-
example = {a: 1, b: 2, c: 3}
|
334
|
-
example.except :a, :b # => {c: 3}
|
335
|
-
example # => {a: 1, b: 2, c: 3}
|
336
|
-
----
|
337
|
-
|
338
|
-
===== #except!
|
339
|
-
|
340
|
-
Answers new hash with given keys removed while mutating itself.
|
341
|
-
|
342
|
-
[source,ruby]
|
343
|
-
----
|
344
|
-
example = {a: 1, b: 2, c: 3}
|
345
|
-
example.except! :a, :b # => {c: 3}
|
346
|
-
example # => {c: 3}
|
347
|
-
----
|
348
|
-
|
349
355
|
===== #flatten_keys
|
350
356
|
|
351
357
|
Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
|
@@ -388,50 +394,6 @@ example.recurse(&:symbolize_keys) # => {a: {b: 1}}
|
|
388
394
|
example.recurse(&:invert) # => {{"b" => 1} => "a"}
|
389
395
|
----
|
390
396
|
|
391
|
-
===== #rekey
|
392
|
-
|
393
|
-
Transforms keys per mapping (size of mapping can vary) without mutating itself.
|
394
|
-
|
395
|
-
[source,ruby]
|
396
|
-
----
|
397
|
-
example = {a: 1, b: 2, c: 3}
|
398
|
-
example.rekey a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
|
399
|
-
example # => {a: 1, b: 2, c: 3}
|
400
|
-
----
|
401
|
-
|
402
|
-
===== #rekey!
|
403
|
-
|
404
|
-
Transforms keys per mapping (size of mapping can vary) while mutating itself.
|
405
|
-
|
406
|
-
[source,ruby]
|
407
|
-
----
|
408
|
-
example = {a: 1, b: 2, c: 3}
|
409
|
-
example.rekey! a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
|
410
|
-
example # => {amber: 1, blue: 2, c: 3}
|
411
|
-
----
|
412
|
-
|
413
|
-
===== #reverse_merge
|
414
|
-
|
415
|
-
Merges calling hash into passed in hash without mutating itself.
|
416
|
-
|
417
|
-
[source,ruby]
|
418
|
-
----
|
419
|
-
example = {a: 1, b: 2}
|
420
|
-
example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
421
|
-
example # => {a: 1, b: 2}
|
422
|
-
----
|
423
|
-
|
424
|
-
===== #reverse_merge!
|
425
|
-
|
426
|
-
Merges calling hash into passed in hash while mutating itself.
|
427
|
-
|
428
|
-
[source,ruby]
|
429
|
-
----
|
430
|
-
example = {a: 1, b: 2}
|
431
|
-
example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
432
|
-
example # => {a: 1, b: 2, c: 3}
|
433
|
-
----
|
434
|
-
|
435
397
|
===== #stringify_keys
|
436
398
|
|
437
399
|
Converts keys to strings without mutating itself.
|
@@ -797,8 +759,8 @@ Updates access and modification times for path. Defaults to current time.
|
|
797
759
|
|
798
760
|
[source,ruby]
|
799
761
|
----
|
800
|
-
Pathname("example.txt").touch
|
801
|
-
Pathname("example.txt").touch
|
762
|
+
Pathname("example.txt").touch # => Pathname("example.txt")
|
763
|
+
Pathname("example.txt").touch Time.now - 1 # => Pathname("example.txt")
|
802
764
|
----
|
803
765
|
|
804
766
|
===== #write
|
data/lib/refinements.rb
CHANGED
data/lib/refinements/arrays.rb
CHANGED
@@ -3,47 +3,27 @@
|
|
3
3
|
module Refinements
|
4
4
|
module Arrays
|
5
5
|
refine Array do
|
6
|
-
def compress
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def including *elements
|
29
|
-
self + elements.flatten
|
30
|
-
end
|
31
|
-
|
32
|
-
def intersperse *elements
|
33
|
-
product([elements]).tap(&:pop).flatten.push last
|
34
|
-
end
|
35
|
-
|
36
|
-
def mean
|
37
|
-
size.zero? ? 0 : sum(0) / size
|
38
|
-
end
|
39
|
-
|
40
|
-
def pad value, max: size
|
41
|
-
dup.fill value, size..(max - 1)
|
42
|
-
end
|
43
|
-
|
44
|
-
def ring &block
|
45
|
-
[last, *self, first].each_cons 3, &block
|
46
|
-
end
|
6
|
+
def compress = compact.reject(&:empty?)
|
7
|
+
|
8
|
+
def compress! = replace(compress)
|
9
|
+
|
10
|
+
def excluding(*elements) = self - elements.flatten
|
11
|
+
|
12
|
+
def filter_find(&block) = block ? lazy.map(&block).find(&:itself) : lazy
|
13
|
+
|
14
|
+
def including(*elements) = self + elements.flatten
|
15
|
+
|
16
|
+
def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)
|
17
|
+
|
18
|
+
def maximum(key) = map(&key).max
|
19
|
+
|
20
|
+
def mean = size.zero? ? 0 : sum(0) / size
|
21
|
+
|
22
|
+
def minimum(key) = map(&key).min
|
23
|
+
|
24
|
+
def pad(value, max: size) = dup.fill(value, size..(max - 1))
|
25
|
+
|
26
|
+
def ring(&block) = [last, *self, first].each_cons(3, &block)
|
47
27
|
end
|
48
28
|
end
|
49
29
|
end
|
@@ -5,9 +5,7 @@ require "bigdecimal"
|
|
5
5
|
module Refinements
|
6
6
|
module BigDecimals
|
7
7
|
refine BigDecimal do
|
8
|
-
def inspect
|
9
|
-
format "#<BigDecimal:%{id} %{string}>", id: object_id, string: to_s("F")
|
10
|
-
end
|
8
|
+
def inspect = format("#<BigDecimal:%{id} %{string}>", id: object_id, string: to_s("F"))
|
11
9
|
end
|
12
10
|
end
|
13
11
|
end
|
data/lib/refinements/hashes.rb
CHANGED
@@ -7,9 +7,7 @@ module Refinements
|
|
7
7
|
new { |new_hash, missing_key| new_hash[missing_key] = new(&new_hash.default_proc) }
|
8
8
|
end
|
9
9
|
|
10
|
-
def with_default value
|
11
|
-
new { |new_hash, missing_key| new_hash[missing_key] = value }
|
12
|
-
end
|
10
|
+
def with_default(value) = new { |new_hash, missing_key| new_hash[missing_key] = value }
|
13
11
|
end
|
14
12
|
|
15
13
|
refine Hash do
|
@@ -25,33 +23,15 @@ module Refinements
|
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
def deep_merge! other
|
29
|
-
replace deep_merge(other)
|
30
|
-
end
|
31
|
-
|
32
|
-
def deep_stringify_keys
|
33
|
-
recurse(&:stringify_keys)
|
34
|
-
end
|
35
|
-
|
36
|
-
def deep_stringify_keys!
|
37
|
-
replace deep_stringify_keys
|
38
|
-
end
|
26
|
+
def deep_merge!(other) = replace(deep_merge(other))
|
39
27
|
|
40
|
-
def
|
41
|
-
recurse(&:symbolize_keys)
|
42
|
-
end
|
28
|
+
def deep_stringify_keys = recurse(&:stringify_keys)
|
43
29
|
|
44
|
-
def
|
45
|
-
replace deep_symbolize_keys
|
46
|
-
end
|
30
|
+
def deep_stringify_keys! = replace(deep_stringify_keys)
|
47
31
|
|
48
|
-
def
|
49
|
-
reject { |key, _value| keys.include? key }
|
50
|
-
end
|
32
|
+
def deep_symbolize_keys = recurse(&:symbolize_keys)
|
51
33
|
|
52
|
-
def
|
53
|
-
replace except(*keys)
|
54
|
-
end
|
34
|
+
def deep_symbolize_keys! = replace(deep_symbolize_keys)
|
55
35
|
|
56
36
|
# :reek:TooManyStatements
|
57
37
|
def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
|
@@ -82,41 +62,13 @@ module Refinements
|
|
82
62
|
end
|
83
63
|
end
|
84
64
|
|
85
|
-
def
|
86
|
-
return self if mapping.empty?
|
65
|
+
def stringify_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
87
66
|
|
88
|
-
|
89
|
-
end
|
67
|
+
def stringify_keys! = replace(stringify_keys)
|
90
68
|
|
91
|
-
def
|
92
|
-
replace rekey(mapping)
|
93
|
-
end
|
69
|
+
def symbolize_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
94
70
|
|
95
|
-
def
|
96
|
-
warn "[DEPRECATION]: #reverse_merge is deprecated, use #merge instead."
|
97
|
-
merge(other) { |_key, old_value, _new_value| old_value }
|
98
|
-
end
|
99
|
-
|
100
|
-
def reverse_merge! other
|
101
|
-
warn "[DEPRECATION]: #reverse_merge! is deprecated, use #merge! instead."
|
102
|
-
replace reverse_merge(other)
|
103
|
-
end
|
104
|
-
|
105
|
-
def stringify_keys
|
106
|
-
reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
107
|
-
end
|
108
|
-
|
109
|
-
def stringify_keys!
|
110
|
-
replace stringify_keys
|
111
|
-
end
|
112
|
-
|
113
|
-
def symbolize_keys
|
114
|
-
reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
115
|
-
end
|
116
|
-
|
117
|
-
def symbolize_keys!
|
118
|
-
replace symbolize_keys
|
119
|
-
end
|
71
|
+
def symbolize_keys! = replace(symbolize_keys)
|
120
72
|
|
121
73
|
def use &block
|
122
74
|
return [] unless block
|
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/ios.rb
CHANGED
@@ -23,13 +23,9 @@ module Refinements
|
|
23
23
|
reopen backup
|
24
24
|
end
|
25
25
|
|
26
|
-
def reread
|
27
|
-
tap(&:rewind).read length, buffer
|
28
|
-
end
|
26
|
+
def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
|
29
27
|
|
30
|
-
def squelch &block
|
31
|
-
self.class.void.then { |void| redirect(void, &block) }
|
32
|
-
end
|
28
|
+
def squelch(&block) = self.class.void.then { |void| redirect(void, &block) }
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -5,6 +5,7 @@ require "pathname"
|
|
5
5
|
module Refinements
|
6
6
|
module Pathnames
|
7
7
|
refine Kernel do
|
8
|
+
# :reek:UncommunicativeMethodName
|
8
9
|
def Pathname object
|
9
10
|
return super(String(object)) unless object
|
10
11
|
|
@@ -13,9 +14,7 @@ module Refinements
|
|
13
14
|
end
|
14
15
|
|
15
16
|
refine Pathname.singleton_class do
|
16
|
-
def home
|
17
|
-
new ENV["HOME"]
|
18
|
-
end
|
17
|
+
def home = new(ENV["HOME"])
|
19
18
|
|
20
19
|
def make_temp_dir prefix: "temp-", suffix: nil, root: nil
|
21
20
|
Dir.mktmpdir([prefix, suffix], root) { |path| block_given? ? yield(new path) : new(path) }
|
@@ -25,9 +24,7 @@ module Refinements
|
|
25
24
|
new(root).files(pattern).each { |path| require path.to_s }
|
26
25
|
end
|
27
26
|
|
28
|
-
def root
|
29
|
-
new "/"
|
30
|
-
end
|
27
|
+
def root = new("/")
|
31
28
|
end
|
32
29
|
|
33
30
|
refine Pathname do
|
@@ -45,64 +42,38 @@ module Refinements
|
|
45
42
|
glob(pattern, flag).select(&:directory?).sort
|
46
43
|
end
|
47
44
|
|
48
|
-
def extensions
|
49
|
-
basename.to_s.split(/(?=\.)+/).tap(&:shift)
|
50
|
-
end
|
45
|
+
def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
|
51
46
|
|
52
|
-
def files
|
53
|
-
glob(pattern, flag).select(&:file?).sort
|
54
|
-
end
|
47
|
+
def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?).sort
|
55
48
|
|
56
|
-
def gsub pattern, replacement
|
57
|
-
self.class.new to_s.gsub(pattern, replacement)
|
58
|
-
end
|
49
|
+
def gsub(pattern, replacement) = self.class.new(to_s.gsub(pattern, replacement))
|
59
50
|
|
60
51
|
def make_ancestors
|
61
52
|
dirname.mkpath
|
62
53
|
self
|
63
54
|
end
|
64
55
|
|
65
|
-
def make_dir
|
66
|
-
exist? ? self : mkdir and self
|
67
|
-
end
|
56
|
+
def make_dir = exist? ? self : (mkdir and self)
|
68
57
|
|
69
58
|
def make_path
|
70
59
|
mkpath
|
71
60
|
self
|
72
61
|
end
|
73
62
|
|
74
|
-
def
|
75
|
-
exist? ? self : super and self
|
76
|
-
end
|
77
|
-
|
78
|
-
def name
|
79
|
-
basename extname
|
80
|
-
end
|
63
|
+
def name = basename(extname)
|
81
64
|
|
82
|
-
def relative_parent root_dir
|
83
|
-
relative_path_from(root_dir).parent
|
84
|
-
end
|
65
|
+
def relative_parent(root_dir) = relative_path_from(root_dir).parent
|
85
66
|
|
86
|
-
def
|
87
|
-
warn "[DEPRECATION]: Pathname#relative_parent_from is deprecated, " \
|
88
|
-
"use Pathname#relative_parent instead."
|
89
|
-
relative_parent root_dir
|
90
|
-
end
|
91
|
-
|
92
|
-
def remove_dir
|
93
|
-
exist? ? (rmdir and self) : self
|
94
|
-
end
|
67
|
+
def remove_dir = exist? ? (rmdir and self) : self
|
95
68
|
|
96
69
|
def remove_tree
|
97
70
|
rmtree if exist?
|
98
71
|
self
|
99
72
|
end
|
100
73
|
|
101
|
-
def rewrite
|
102
|
-
read.then { |content| write yield(content) if block_given? }
|
103
|
-
end
|
74
|
+
def rewrite = read.then { |content| write yield(content) if block_given? }
|
104
75
|
|
105
|
-
def touch at
|
76
|
+
def touch at = Time.now
|
106
77
|
exist? ? utime(at, at) : write("")
|
107
78
|
self
|
108
79
|
end
|
data/lib/refinements/strings.rb
CHANGED
@@ -2,19 +2,10 @@
|
|
2
2
|
|
3
3
|
module Refinements
|
4
4
|
module Strings
|
5
|
-
DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
|
6
|
-
|
7
|
-
refine String.singleton_class do
|
8
|
-
def delimiters
|
9
|
-
warn "[DEPRECATION]: .delimiters is deprecated, use DELIMITERS instead."
|
10
|
-
DELIMITERS
|
11
|
-
end
|
12
|
-
end
|
5
|
+
DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
|
13
6
|
|
14
7
|
refine String do
|
15
|
-
def blank?
|
16
|
-
match?(/\A\s*\z/)
|
17
|
-
end
|
8
|
+
def blank? = match?(/\A\s*\z/)
|
18
9
|
|
19
10
|
def camelcase
|
20
11
|
return up unless match? DELIMITERS
|
@@ -74,9 +65,7 @@ module Refinements
|
|
74
65
|
.then { |parts| combine parts, :up, "/" }
|
75
66
|
end
|
76
67
|
|
77
|
-
def to_bool
|
78
|
-
%w[true yes on t y 1].include? downcase.strip
|
79
|
-
end
|
68
|
+
def to_bool = %w[true yes on t y 1].include?(downcase.strip)
|
80
69
|
|
81
70
|
def up
|
82
71
|
return self if empty?
|
data/lib/refinements/structs.rb
CHANGED
@@ -3,35 +3,25 @@
|
|
3
3
|
module Refinements
|
4
4
|
module Structs
|
5
5
|
refine Struct.singleton_class do
|
6
|
-
def keyworded?
|
7
|
-
inspect.include? "keyword_init: true"
|
8
|
-
end
|
6
|
+
def keyworded? = inspect.include?("keyword_init: true")
|
9
7
|
|
10
|
-
def with_keywords arguments
|
11
|
-
keyworded? ? new(arguments) : new.merge!(arguments)
|
12
|
-
end
|
8
|
+
def with_keywords(**arguments) = keyworded? ? new(**arguments) : new.merge!(**arguments)
|
13
9
|
|
14
|
-
def with_positions *values
|
15
|
-
keyworded? ? new(Hash[members.zip values]) : new(*values)
|
16
|
-
end
|
10
|
+
def with_positions(*values) = keyworded? ? new(**members.zip(values).to_h) : new(*values)
|
17
11
|
end
|
18
12
|
|
19
13
|
refine Struct do
|
20
|
-
def merge **attributes
|
21
|
-
dup.merge! attributes
|
22
|
-
end
|
14
|
+
def merge(**attributes) = dup.merge!(**attributes)
|
23
15
|
|
24
16
|
def merge! **attributes
|
25
|
-
to_h.merge(attributes).each { |key, value| self[key] = value }
|
17
|
+
to_h.merge(**attributes).each { |key, value| self[key] = value }
|
26
18
|
self
|
27
19
|
end
|
28
20
|
|
29
21
|
def revalue attributes = each_pair
|
30
22
|
return self unless block_given?
|
31
23
|
|
32
|
-
dup.tap
|
33
|
-
attributes.each { |key, value| copy[key] = yield self[key], value }
|
34
|
-
end
|
24
|
+
dup.tap { |copy| attributes.each { |key, value| copy[key] = yield self[key], value } }
|
35
25
|
end
|
36
26
|
|
37
27
|
def revalue! attributes = each_pair
|
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: 8.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIC/
|
14
|
-
|
15
|
-
|
13
|
+
MIIC/jCCAeagAwIBAgIBBDANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
|
14
|
+
a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMTAzMTkxMjQ4MDZaFw0yMjAzMTkx
|
15
|
+
MjQ4MDZaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
|
16
16
|
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
|
17
17
|
xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
|
18
18
|
brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
|
@@ -20,15 +20,15 @@ cert_chain:
|
|
20
20
|
D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
|
21
21
|
3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
|
22
22
|
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
|
23
|
-
2CdikiiE3fJhP/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAEjpaOXHHp8s/7GL2qCb
|
24
|
+
YAs7urOLv9VHSPfQWAwaTMVnSsIf3Sw4xzISOP/mmfEPBPXtz61K5esrE/uTFtgb
|
25
|
+
FyjxQk2H0sEWgrRXGGNHBWQRhhEs7LP/TByoC15A0br++xLxRz4r7HBLGAWQQDpg
|
26
|
+
66BJ2TBVjxS6K64tKbq7+ACyrOZGgTfNHACh4M076y0x0oRf/rwBrU39/KRfuhbb
|
27
|
+
cm+nNCEtO35gTmZ2bVDHLGvWazi3gJt6+huQjfXTCUUG2YYBxwhu+GPdAGQPxpf9
|
28
|
+
lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
|
29
|
+
W2A=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date:
|
31
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
32
32
|
dependencies: []
|
33
33
|
description:
|
34
34
|
email:
|
@@ -45,7 +45,6 @@ files:
|
|
45
45
|
- lib/refinements/arrays.rb
|
46
46
|
- lib/refinements/big_decimals.rb
|
47
47
|
- lib/refinements/date_times.rb
|
48
|
-
- lib/refinements/files.rb
|
49
48
|
- lib/refinements/hashes.rb
|
50
49
|
- lib/refinements/identity.rb
|
51
50
|
- lib/refinements/ios.rb
|
@@ -69,14 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
68
|
requirements:
|
70
69
|
- - "~>"
|
71
70
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
71
|
+
version: '3.0'
|
73
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
73
|
requirements:
|
75
74
|
- - ">="
|
76
75
|
- !ruby/object:Gem::Version
|
77
76
|
version: '0'
|
78
77
|
requirements: []
|
79
|
-
rubygems_version: 3.2.
|
78
|
+
rubygems_version: 3.2.17
|
80
79
|
signing_key:
|
81
80
|
specification_version: 4
|
82
81
|
summary: A collection of refinements to core Ruby objects.
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/refinements/files.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Refinements
|
4
|
-
module Files
|
5
|
-
refine File.singleton_class do
|
6
|
-
def rewrite path
|
7
|
-
warn "[DEPRECATION]: File.rewrite is deprecated, use Pathname#rewrite instead."
|
8
|
-
read(path).then { |content| write path, yield(content) }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|