refinements 7.9.0 → 7.10.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 +84 -22
- data/lib/refinements/hashes.rb +16 -0
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/strings.rb +6 -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: 2b7b36399c299675bc98b26334acc2466c5c506849e34b36534f21d2eed72e57
|
4
|
+
data.tar.gz: 0d00c8e399a0d43c21dafef5985e9d0eb51fe7d544fbe93f4d184eafa75018a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 558191fc552ba160302b9189b8bd2e3ed17ceaee226426cf9453c0c65b8ca0e771b9e85be1e5453c8c1438bc52511a45afc218c72329c17570a6036b65e9f91f
|
7
|
+
data.tar.gz: 69436b5353f1541b644f9ca72346da713bd8bb1c0f9595983392881727f06ea46ecacdea1412a929981ee24e0243865c6ac9274e747f04d3584c85216e7e300b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -9,7 +9,7 @@ image::https://badge.fury.io/rb/refinements.svg[Gem Version]
|
|
9
9
|
[link=https://circleci.com/gh/bkuhlmann/refinements]
|
10
10
|
image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
|
11
11
|
|
12
|
-
A collection of refinements (enhancements) to
|
12
|
+
A collection of refinements (enhancements) to primitive Ruby objects.
|
13
13
|
|
14
14
|
toc::[]
|
15
15
|
|
@@ -95,7 +95,8 @@ require "refinements/string_ios"
|
|
95
95
|
|
96
96
|
=== Using
|
97
97
|
|
98
|
-
Much like including/extending a module, you’ll need modify your object(s) to use the
|
98
|
+
Much like including/extending a module, you’ll need to modify your object(s) to use the
|
99
|
+
refinement(s):
|
99
100
|
|
100
101
|
[source,ruby]
|
101
102
|
----
|
@@ -119,7 +120,7 @@ The following sections demonstrate how each refinement enriches your objects wit
|
|
119
120
|
|
120
121
|
===== #compress
|
121
122
|
|
122
|
-
Removes `nil` and empty values without
|
123
|
+
Removes `nil` and empty values without mutating itself.
|
123
124
|
|
124
125
|
[source,ruby]
|
125
126
|
----
|
@@ -130,7 +131,7 @@ example # => ["An", nil, "", "Example"]
|
|
130
131
|
|
131
132
|
===== #compress!
|
132
133
|
|
133
|
-
Removes `nil` and empty values while
|
134
|
+
Removes `nil` and empty values while mutating itself.
|
134
135
|
|
135
136
|
[source,ruby]
|
136
137
|
----
|
@@ -141,7 +142,7 @@ example # => ["An", "Example"]
|
|
141
142
|
|
142
143
|
===== #include
|
143
144
|
|
144
|
-
Adds given array or elements without
|
145
|
+
Adds given array or elements without mutating itself.
|
145
146
|
|
146
147
|
[source,ruby]
|
147
148
|
----
|
@@ -151,7 +152,7 @@ Adds given array or elements without modifying itself.
|
|
151
152
|
|
152
153
|
===== #exclude
|
153
154
|
|
154
|
-
Removes given array or elements without
|
155
|
+
Removes given array or elements without mutating itself.
|
155
156
|
|
156
157
|
[source,ruby]
|
157
158
|
----
|
@@ -236,7 +237,7 @@ example[:b] # => []
|
|
236
237
|
|
237
238
|
===== #except
|
238
239
|
|
239
|
-
Answers new hash with given keys removed without
|
240
|
+
Answers new hash with given keys removed without mutating itself.
|
240
241
|
|
241
242
|
[source,ruby]
|
242
243
|
----
|
@@ -247,7 +248,7 @@ example # => {a: 1, b: 2, c: 3}
|
|
247
248
|
|
248
249
|
===== #except!
|
249
250
|
|
250
|
-
Answers new hash with given keys removed while
|
251
|
+
Answers new hash with given keys removed while mutating itself.
|
251
252
|
|
252
253
|
[source,ruby]
|
253
254
|
----
|
@@ -258,7 +259,7 @@ example # => {c: 3}
|
|
258
259
|
|
259
260
|
===== #flatten_keys
|
260
261
|
|
261
|
-
Flattens nested keys as top-level keys without
|
262
|
+
Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
|
262
263
|
though.
|
263
264
|
|
264
265
|
[source,ruby]
|
@@ -276,7 +277,7 @@ example # => {a: {b: 1}}
|
|
276
277
|
|
277
278
|
===== #flatten_keys!
|
278
279
|
|
279
|
-
Flattens nested keys as top-level keys while
|
280
|
+
Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays,
|
280
281
|
though.
|
281
282
|
|
282
283
|
[source,ruby]
|
@@ -286,9 +287,31 @@ example.flatten_keys! # => {a_b: 1}
|
|
286
287
|
example # => {a_b: 1}
|
287
288
|
----
|
288
289
|
|
290
|
+
===== #stringify_keys
|
291
|
+
|
292
|
+
Converts keys to strings without mutating itself.
|
293
|
+
|
294
|
+
[source,ruby]
|
295
|
+
----
|
296
|
+
example = {a: 1, b: 2}
|
297
|
+
example.stringify_keys # => {"a" => 1, "b" => 2}
|
298
|
+
example # => {a: 1, b: 2}
|
299
|
+
----
|
300
|
+
|
301
|
+
===== #stringify_keys!
|
302
|
+
|
303
|
+
Converts keys to strings while mutating itself.
|
304
|
+
|
305
|
+
[source,ruby]
|
306
|
+
----
|
307
|
+
example = {a: 1, b: 2}
|
308
|
+
example.stringify_keys! # => {"a" => 1, "b" => 2}
|
309
|
+
example # => {"a" => 1, "b" => 2}
|
310
|
+
----
|
311
|
+
|
289
312
|
===== #symbolize_keys
|
290
313
|
|
291
|
-
Converts keys to symbols without
|
314
|
+
Converts keys to symbols without mutating itself.
|
292
315
|
|
293
316
|
[source,ruby]
|
294
317
|
----
|
@@ -299,7 +322,7 @@ example # => {"a" => 1, "b" => 2}
|
|
299
322
|
|
300
323
|
===== #symbolize_keys!
|
301
324
|
|
302
|
-
Converts keys to symbols while
|
325
|
+
Converts keys to symbols while mutating itself.
|
303
326
|
|
304
327
|
[source,ruby]
|
305
328
|
----
|
@@ -310,7 +333,7 @@ example # => {a: 1, b: 2}
|
|
310
333
|
|
311
334
|
===== #deep_merge
|
312
335
|
|
313
|
-
Merges deeply nested hashes together without
|
336
|
+
Merges deeply nested hashes together without mutating itself.
|
314
337
|
|
315
338
|
[source,ruby]
|
316
339
|
----
|
@@ -321,7 +344,7 @@ example # => {a: "A", b: {one: "One", two: "Two"}}
|
|
321
344
|
|
322
345
|
===== #deep_merge!
|
323
346
|
|
324
|
-
Merges deeply nested hashes together while
|
347
|
+
Merges deeply nested hashes together while mutating itself.
|
325
348
|
|
326
349
|
[source,ruby]
|
327
350
|
----
|
@@ -330,9 +353,31 @@ example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
|
|
330
353
|
example # => {a: "A", b: {one: 1, two: "Two"}}
|
331
354
|
----
|
332
355
|
|
356
|
+
===== #deep_stringify_keys
|
357
|
+
|
358
|
+
Stringifies keys of nested hash without mutating itself. Does not handle nested arrays, though.
|
359
|
+
|
360
|
+
[source,ruby]
|
361
|
+
----
|
362
|
+
example = {a: {b: 2}}
|
363
|
+
example.deep_stringify_keys # => {"a" => {"b" => 1}}
|
364
|
+
example # => {a: {b: 2}}
|
365
|
+
----
|
366
|
+
|
367
|
+
===== #deep_stringify_keys!
|
368
|
+
|
369
|
+
Stringifies keys of nested hash while mutating itself. Does not handle nested arrays, though.
|
370
|
+
|
371
|
+
[source,ruby]
|
372
|
+
----
|
373
|
+
example = {a: {b: 2}}
|
374
|
+
example.deep_stringify_keys! # => {"a" => {"b" => 1}}
|
375
|
+
example # => {"a" => {"b" => 1}}
|
376
|
+
----
|
377
|
+
|
333
378
|
===== #deep_symbolize_keys
|
334
379
|
|
335
|
-
Symbolizes keys of nested hash without
|
380
|
+
Symbolizes keys of nested hash without mutating itself. Does not handle nested arrays, though.
|
336
381
|
|
337
382
|
[source,ruby]
|
338
383
|
----
|
@@ -343,7 +388,7 @@ example # => {"a" => {"b" => 2}}
|
|
343
388
|
|
344
389
|
===== #deep_symbolize_keys!
|
345
390
|
|
346
|
-
Symbolizes keys of nested hash while
|
391
|
+
Symbolizes keys of nested hash while mutating itself. Does not handle nested arrays, though.
|
347
392
|
|
348
393
|
[source,ruby]
|
349
394
|
----
|
@@ -354,7 +399,8 @@ example # => {a: {b: 1}}
|
|
354
399
|
|
355
400
|
===== #recurse
|
356
401
|
|
357
|
-
|
402
|
+
Recursively iterates over the hash and any hash value by applying the given block to it. Does not
|
403
|
+
handle nested arrays, though.
|
358
404
|
|
359
405
|
[source,ruby]
|
360
406
|
----
|
@@ -365,7 +411,7 @@ example.recurse(&:invert) # => {{"b" => 1} => "a"}
|
|
365
411
|
|
366
412
|
===== #rekey
|
367
413
|
|
368
|
-
Transforms keys per mapping (size of mapping can vary) without
|
414
|
+
Transforms keys per mapping (size of mapping can vary) without mutating itself.
|
369
415
|
|
370
416
|
[source,ruby]
|
371
417
|
----
|
@@ -376,7 +422,7 @@ example # => {a: 1, b: 2, c: 3}
|
|
376
422
|
|
377
423
|
===== #rekey!
|
378
424
|
|
379
|
-
Transforms keys per mapping (size of mapping can vary) while
|
425
|
+
Transforms keys per mapping (size of mapping can vary) while mutating itself.
|
380
426
|
|
381
427
|
[source,ruby]
|
382
428
|
----
|
@@ -387,7 +433,7 @@ example # => {amber: 1, blue: 2, c: 3}
|
|
387
433
|
|
388
434
|
===== #reverse_merge
|
389
435
|
|
390
|
-
Merges calling hash into passed in hash without
|
436
|
+
Merges calling hash into passed in hash without mutating itself.
|
391
437
|
|
392
438
|
[source,ruby]
|
393
439
|
----
|
@@ -398,7 +444,7 @@ example # => {a: 1, b: 2}
|
|
398
444
|
|
399
445
|
===== #reverse_merge!
|
400
446
|
|
401
|
-
Merges calling hash into passed in hash while
|
447
|
+
Merges calling hash into passed in hash while mutating itself.
|
402
448
|
|
403
449
|
[source,ruby]
|
404
450
|
----
|
@@ -421,7 +467,10 @@ example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
|
|
421
467
|
|
422
468
|
===== Pathname
|
423
469
|
|
424
|
-
|
470
|
+
Enhances the conversion function -- refined from `Kernel` -- which casts `nil` into a pathname in
|
471
|
+
order to avoid: `TypeError (no implicit conversion of nil into String)`. The pathname is still
|
472
|
+
invalid but at least you have an instance of `Pathname`, which behaves like a _Null Object_, that
|
473
|
+
can still be used to construct a valid path.
|
425
474
|
|
426
475
|
[source,ruby]
|
427
476
|
----
|
@@ -579,6 +628,19 @@ Answers string with only first letter downcased.
|
|
579
628
|
"EXAMPLE".down # => "eXAMPLE"
|
580
629
|
----
|
581
630
|
|
631
|
+
===== #indent
|
632
|
+
|
633
|
+
Answers string indented by two spaces by default.
|
634
|
+
|
635
|
+
[source,ruby]
|
636
|
+
----
|
637
|
+
"example".indent # => " example"
|
638
|
+
"example".indent 0 # => "example"
|
639
|
+
"example".indent -1 # => "example"
|
640
|
+
"example".indent 2 # => " example"
|
641
|
+
"example".indent 3, padding: " " # => " example"
|
642
|
+
----
|
643
|
+
|
582
644
|
===== #camelcase
|
583
645
|
|
584
646
|
Answers a camelcased string.
|
data/lib/refinements/hashes.rb
CHANGED
@@ -40,6 +40,14 @@ module Refinements
|
|
40
40
|
replace flatten_keys(prefix: prefix, delimiter: delimiter, cast: cast)
|
41
41
|
end
|
42
42
|
|
43
|
+
def stringify_keys
|
44
|
+
reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
45
|
+
end
|
46
|
+
|
47
|
+
def stringify_keys!
|
48
|
+
replace stringify_keys
|
49
|
+
end
|
50
|
+
|
43
51
|
def symbolize_keys
|
44
52
|
reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
45
53
|
end
|
@@ -64,6 +72,14 @@ module Refinements
|
|
64
72
|
replace deep_merge(other)
|
65
73
|
end
|
66
74
|
|
75
|
+
def deep_stringify_keys
|
76
|
+
recurse(&:stringify_keys)
|
77
|
+
end
|
78
|
+
|
79
|
+
def deep_stringify_keys!
|
80
|
+
replace deep_stringify_keys
|
81
|
+
end
|
82
|
+
|
67
83
|
def deep_symbolize_keys
|
68
84
|
recurse(&:symbolize_keys)
|
69
85
|
end
|
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/strings.rb
CHANGED
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.10.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-09-
|
31
|
+
date: 2020-09-27 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
|