refinements 7.12.0 → 7.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3df95fcb46ec44d2945b1eb3ab7dafd8ba6bb243973829d662e448ef74695302
4
- data.tar.gz: 21d89890312770ec2c73387c05c44dc31b22de849e18c3db6b4248476ca8bbdf
3
+ metadata.gz: 58f24ccfa83d2f2af820c05d19c575e371ed5c6471177c8c58648006cf3ca945
4
+ data.tar.gz: 7fccb86818487e2de337969b42c8ec81f52e28bc1a3edb1d8cc0bf2c206ee2b0
5
5
  SHA512:
6
- metadata.gz: d0cb8fa10183e03737eab0ae1780b91e2e4ce994fd0945c7e2653bacd852dae85de474a073f4b1f6b8634e685059a54a0651b46ec567defd283cfb1491988e50
7
- data.tar.gz: a3f2ea6940f0e8c74f41f43d28d34a71892d3ddcaaf295c64ce4761b120421f80c7833bd9b48d37a90e485c3b606c38adb71e8665cf9feecad35925da485628a
6
+ metadata.gz: 773c5bf918f8e7f958dc602b9c6d7edefc29d644d7d928db0f21e2fa93616781e075b1c4743281b025daf8335c13761d460d149caa470c8000a11aecc91f25f8
7
+ data.tar.gz: 1cbe58132380e683a0e47813fe676440055fa2a9af1bd582bf8661c3778b1aa354cda5d3939f07b69a6190f72b28e9635890aaa6810af7c9255fef27c025e1a5
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,6 +6,8 @@
6
6
 
7
7
  [link=http://badge.fury.io/rb/refinements]
8
8
  image::https://badge.fury.io/rb/refinements.svg[Gem Version]
9
+ [link=https://www.alchemists.io/projects/code_quality]
10
+ image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
9
11
  [link=https://circleci.com/gh/bkuhlmann/refinements]
10
12
  image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
11
13
 
@@ -123,6 +125,16 @@ example.compress! # => ["An", "Example"]
123
125
  example # => ["An", "Example"]
124
126
  ----
125
127
 
128
+ ===== #exclude
129
+
130
+ Removes given array or elements without mutating itself.
131
+
132
+ [source,ruby]
133
+ ----
134
+ [1, 2, 3, 4, 5].exclude [4, 5] # => [1, 2, 3]
135
+ [1, 2, 3, 4, 5].exclude 4, 5 # => [1, 2, 3]
136
+ ----
137
+
126
138
  ===== #include
127
139
 
128
140
  Adds given array or elements without mutating itself.
@@ -144,16 +156,6 @@ Inserts additional elements or array between all members of given array.
144
156
  [1, 2, 3].intersperse %i[a b c] # => [1, :a, :b, :c, 2, :a, :b, :c, 3]
145
157
  ----
146
158
 
147
- ===== #exclude
148
-
149
- Removes given array or elements without mutating itself.
150
-
151
- [source,ruby]
152
- ----
153
- [1, 2, 3, 4, 5].exclude [4, 5] # => [1, 2, 3]
154
- [1, 2, 3, 4, 5].exclude 4, 5 # => [1, 2, 3]
155
- ----
156
-
157
159
  ===== #mean
158
160
 
159
161
  Answers mean/average all elements within an array.
@@ -241,102 +243,6 @@ example = Hash.with_default []
241
243
  example[:b] # => []
242
244
  ----
243
245
 
244
- ===== #except
245
-
246
- Answers new hash with given keys removed without mutating itself.
247
-
248
- [source,ruby]
249
- ----
250
- example = {a: 1, b: 2, c: 3}
251
- example.except :a, :b # => {c: 3}
252
- example # => {a: 1, b: 2, c: 3}
253
- ----
254
-
255
- ===== #except!
256
-
257
- Answers new hash with given keys removed while mutating itself.
258
-
259
- [source,ruby]
260
- ----
261
- example = {a: 1, b: 2, c: 3}
262
- example.except! :a, :b # => {c: 3}
263
- example # => {c: 3}
264
- ----
265
-
266
- ===== #flatten_keys
267
-
268
- Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
269
- though.
270
-
271
- [source,ruby]
272
- ----
273
- {a: {b: 1}}.flatten_keys prefix: :test # => {test_a_b: 1}
274
- {a: {b: 1}}.flatten_keys delimiter: :| # => {:"a|b" => 1}
275
-
276
- {a: {b: 1}}.flatten_keys cast: :to_s # => {"a_b" => 1}
277
- {"a" => {"b" => 1}}.flatten_keys cast: :to_sym # => {a_b: 1}
278
-
279
- example = {a: {b: 1}}
280
- example.flatten_keys # => {a_b: 1}
281
- example # => {a: {b: 1}}
282
- ----
283
-
284
- ===== #flatten_keys!
285
-
286
- Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays,
287
- though.
288
-
289
- [source,ruby]
290
- ----
291
- example = {a: {b: 1}}
292
- example.flatten_keys! # => {a_b: 1}
293
- example # => {a_b: 1}
294
- ----
295
-
296
- ===== #stringify_keys
297
-
298
- Converts keys to strings without mutating itself.
299
-
300
- [source,ruby]
301
- ----
302
- example = {a: 1, b: 2}
303
- example.stringify_keys # => {"a" => 1, "b" => 2}
304
- example # => {a: 1, b: 2}
305
- ----
306
-
307
- ===== #stringify_keys!
308
-
309
- Converts keys to strings while mutating itself.
310
-
311
- [source,ruby]
312
- ----
313
- example = {a: 1, b: 2}
314
- example.stringify_keys! # => {"a" => 1, "b" => 2}
315
- example # => {"a" => 1, "b" => 2}
316
- ----
317
-
318
- ===== #symbolize_keys
319
-
320
- Converts keys to symbols without mutating itself.
321
-
322
- [source,ruby]
323
- ----
324
- example = {"a" => 1, "b" => 2}
325
- example.symbolize_keys # => {a: 1, b: 2}
326
- example # => {"a" => 1, "b" => 2}
327
- ----
328
-
329
- ===== #symbolize_keys!
330
-
331
- Converts keys to symbols while mutating itself.
332
-
333
- [source,ruby]
334
- ----
335
- example = {"a" => 1, "b" => 2}
336
- example.symbolize_keys! # => {a: 1, b: 2}
337
- example # => {a: 1, b: 2}
338
- ----
339
-
340
246
  ===== #deep_merge
341
247
 
342
248
  Merges deeply nested hashes together without mutating itself.
@@ -403,6 +309,58 @@ example.deep_symbolize_keys! # => {a: {b: 1}}
403
309
  example # => {a: {b: 1}}
404
310
  ----
405
311
 
312
+ ===== #except
313
+
314
+ Answers new hash with given keys removed without mutating itself.
315
+
316
+ [source,ruby]
317
+ ----
318
+ example = {a: 1, b: 2, c: 3}
319
+ example.except :a, :b # => {c: 3}
320
+ example # => {a: 1, b: 2, c: 3}
321
+ ----
322
+
323
+ ===== #except!
324
+
325
+ Answers new hash with given keys removed while mutating itself.
326
+
327
+ [source,ruby]
328
+ ----
329
+ example = {a: 1, b: 2, c: 3}
330
+ example.except! :a, :b # => {c: 3}
331
+ example # => {c: 3}
332
+ ----
333
+
334
+ ===== #flatten_keys
335
+
336
+ Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
337
+ though.
338
+
339
+ [source,ruby]
340
+ ----
341
+ {a: {b: 1}}.flatten_keys prefix: :test # => {test_a_b: 1}
342
+ {a: {b: 1}}.flatten_keys delimiter: :| # => {:"a|b" => 1}
343
+
344
+ {a: {b: 1}}.flatten_keys cast: :to_s # => {"a_b" => 1}
345
+ {"a" => {"b" => 1}}.flatten_keys cast: :to_sym # => {a_b: 1}
346
+
347
+ example = {a: {b: 1}}
348
+ example.flatten_keys # => {a_b: 1}
349
+ example # => {a: {b: 1}}
350
+ ----
351
+
352
+ ===== #flatten_keys!
353
+
354
+ Flattens nested keys as top-level keys while mutating itself. Does not handle nested arrays,
355
+ though.
356
+
357
+ [source,ruby]
358
+ ----
359
+ example = {a: {b: 1}}
360
+ example.flatten_keys! # => {a_b: 1}
361
+ example # => {a_b: 1}
362
+ ----
363
+
406
364
  ===== #recurse
407
365
 
408
366
  Recursively iterates over the hash and any hash value by applying the given block to it. Does not
@@ -459,6 +417,50 @@ example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
459
417
  example # => {a: 1, b: 2, c: 3}
460
418
  ----
461
419
 
420
+ ===== #stringify_keys
421
+
422
+ Converts keys to strings without mutating itself.
423
+
424
+ [source,ruby]
425
+ ----
426
+ example = {a: 1, b: 2}
427
+ example.stringify_keys # => {"a" => 1, "b" => 2}
428
+ example # => {a: 1, b: 2}
429
+ ----
430
+
431
+ ===== #stringify_keys!
432
+
433
+ Converts keys to strings while mutating itself.
434
+
435
+ [source,ruby]
436
+ ----
437
+ example = {a: 1, b: 2}
438
+ example.stringify_keys! # => {"a" => 1, "b" => 2}
439
+ example # => {"a" => 1, "b" => 2}
440
+ ----
441
+
442
+ ===== #symbolize_keys
443
+
444
+ Converts keys to symbols without mutating itself.
445
+
446
+ [source,ruby]
447
+ ----
448
+ example = {"a" => 1, "b" => 2}
449
+ example.symbolize_keys # => {a: 1, b: 2}
450
+ example # => {"a" => 1, "b" => 2}
451
+ ----
452
+
453
+ ===== #symbolize_keys!
454
+
455
+ Converts keys to symbols while mutating itself.
456
+
457
+ [source,ruby]
458
+ ----
459
+ example = {"a" => 1, "b" => 2}
460
+ example.symbolize_keys! # => {a: 1, b: 2}
461
+ example # => {a: 1, b: 2}
462
+ ----
463
+
462
464
  ===== #use
463
465
 
464
466
  Passes each hash value as a block argument for further processing.
@@ -486,18 +488,6 @@ io = IO.void { |void| void.write "nevermore" }
486
488
  io.closed? # => true
487
489
  ----
488
490
 
489
- ===== #squelch
490
-
491
- Temporarily ignores any reads/writes for current stream for all code executed within the block. When
492
- not given a block, it answers itself.
493
-
494
- [source,ruby]
495
- ----
496
- io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
497
- io.squelch { io.write "Test" }
498
- io.reread # => ""
499
- ----
500
-
501
491
  ===== #redirect
502
492
 
503
493
  Redirects current stream to other stream when given a block. Without a block, the original stream is
@@ -532,6 +522,18 @@ io.reread(buffer: buffer)
532
522
  buffer # => "This is a test."
533
523
  ----
534
524
 
525
+ ===== #squelch
526
+
527
+ Temporarily ignores any reads/writes for current stream for all code executed within the block. When
528
+ not given a block, it answers itself.
529
+
530
+ [source,ruby]
531
+ ----
532
+ io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
533
+ io.squelch { io.write "Test" }
534
+ io.reread # => ""
535
+ ----
536
+
535
537
  ==== Pathname
536
538
 
537
539
  ===== Pathname
@@ -546,13 +548,20 @@ can still be used to construct a valid path.
546
548
  Pathname(nil) # => Pathname("")
547
549
  ----
548
550
 
549
- ===== #name
551
+ ===== #change_dir
550
552
 
551
- Answers file name without extension.
553
+ Inherits and wraps `Dir.chdir` behavior by changing to directory of current path. See
554
+ link:https://rubyapi.org/2.7/o/s?q=Dir.chdir[Dir.chdir] for details.
552
555
 
553
556
  [source,ruby]
554
557
  ----
555
- Pathname("example.txt").name # => Pathname("example")
558
+ Pathname.pwd # => "/"
559
+ Pathname("/test").make_dir.change_dir # => Pathname "/test"
560
+ Pathname.pwd # => "/test"
561
+
562
+ Pathname.pwd # => "/"
563
+ Pathname("/test").make_dir.change_dir { # Implementation details } # => Pathname "/test"
564
+ Pathname.pwd # => "/"
556
565
  ----
557
566
 
558
567
  ===== #copy
@@ -608,78 +617,111 @@ Pathname("/%placeholder%/some/%placeholder%").gsub("%placeholder%", "test")
608
617
  # => Pathname("/test/some/test")
609
618
  ----
610
619
 
611
- ===== #relative_parent
620
+ ===== #make_ancestors
612
621
 
613
- Answers relative path from parent directory. This is a complement to `#relative_path_from`.
622
+ Ensures all ancestor directories are created for a path.
614
623
 
615
624
  [source,ruby]
616
625
  ----
617
- Pathname("/one/two/three").relative_parent("/one") # => Pathname "two"
626
+ Pathname("/one/two").make_ancestors
627
+ Pathname("/one").exist? # => true
628
+ Pathname("/one/two").exist? # => false
618
629
  ----
619
630
 
620
- ===== #make_ancestors
631
+ ===== #make_dir
621
632
 
622
- Ensures all ancestor directories are created for a path.
633
+ Provides alternative `#mkdir` behavior by always answering itself (even when directory exists) and
634
+ not throwing errors when directory does exist in order to ensure the pathname can be chained.
623
635
 
624
636
  [source,ruby]
625
637
  ----
626
- Pathname("/one/two").make_ancestors
627
- Pathname("/one").exist? # => true
628
- Pathname("/one/two").exist? # => false
638
+ Pathname("/one").make_dir # => Pathname("/one")
639
+ Pathname("/one").make_dir.make_dir # => Pathname("/one")
629
640
  ----
630
641
 
631
- ===== #mkdir
642
+ ===== #make_path
632
643
 
633
- Modifies default behavior by always answering itself (even when directory exists) and not throwing
634
- errors when directory exists.
644
+ Provides alternative `#mkpath` behavior by always answering itself (even when full path exists) and
645
+ not throwing errors when directory does exist in order to ensure the pathname can be chained.
635
646
 
636
647
  [source,ruby]
637
648
  ----
638
- Pathname("/one").mkdir # => Pathname("/one")
639
- Pathname("/one").mkdir.mkdir # => Pathname("/one")
649
+ Pathname("/one/two/three").make_path # => Pathname("/one/two/three")
650
+ Pathname("/one/two/three").make_path.make_path # => Pathname("/one/two/three")
640
651
  ----
641
652
 
642
- ===== #rewrite
653
+ ===== #name
643
654
 
644
- When given a block, it provides the contents of the recently read file for manipulation and
645
- immediate writing back to the same file.
655
+ Answers file name without extension.
646
656
 
647
657
  [source,ruby]
648
658
  ----
649
- Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
659
+ Pathname("example.txt").name # => Pathname("example")
650
660
  ----
651
661
 
652
- ===== #touch
662
+ ===== #relative_parent
653
663
 
654
- Updates access and modification times for path. Defaults to current time.
664
+ Answers relative path from parent directory. This is a complement to `#relative_path_from`.
655
665
 
656
666
  [source,ruby]
657
667
  ----
658
- Pathname("example.txt").touch
659
- Pathname("example.txt").touch at: Time.now - 1
668
+ Pathname("/one/two/three").relative_parent("/one") # => Pathname "two"
660
669
  ----
661
670
 
662
- ==== String
671
+ ===== #remove_dir
663
672
 
664
- ===== #first
673
+ Provides alternative `#rmdir` behavior by always answering itself (even when full path exists) and
674
+ not throwing errors when directory does exist in order to ensure the pathname can be chained.
665
675
 
666
- Answers first character of a string or first set of characters if given a number.
676
+ [source,ruby]
677
+ ----
678
+ Pathname("/test").make_dir.remove_dir.exist? # => false
679
+ Pathname("/test").remove_dir # => Pathname("/test")
680
+ Pathname("/test").remove_dir.remove_dir # => Pathname("/test")
681
+ ----
682
+
683
+ ===== #remove_tree
684
+
685
+ Provides alternative `#rmtree` behavior by always answering itself (even when full path exists) and
686
+ not throwing errors when directory does exist in order to ensure the pathname can be chained.
667
687
 
668
688
  [source,ruby]
669
689
  ----
670
- "example".first # => "e"
671
- "example".first 4 # => "exam"
690
+ parent_path = Pathname "/one"
691
+ child_path = parent_path.join "two"
692
+
693
+ child_path.make_path
694
+ child_path.remove_tree # => Pathname "/one/two"
695
+ child_path.exist? # => false
696
+ paremt_path.exist? # => true
697
+
698
+ child_path.make_path
699
+ parent_path.remove_tree # => Pathname "/one"
700
+ child_path.exist? # => false
701
+ parent_path.exist? # => false
672
702
  ----
673
703
 
674
- ===== #last
704
+ ===== #rewrite
675
705
 
676
- Answers last character of a string or last set of characters if given a number.
706
+ When given a block, it provides the contents of the recently read file for manipulation and
707
+ immediate writing back to the same file.
677
708
 
678
709
  [source,ruby]
679
710
  ----
680
- "instant".last # => "t"
681
- "instant".last 3 # => "ant"
711
+ Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
712
+ ----
713
+
714
+ ===== #touch
715
+
716
+ Updates access and modification times for path. Defaults to current time.
717
+
718
+ [source,ruby]
682
719
  ----
720
+ Pathname("example.txt").touch
721
+ Pathname("example.txt").touch at: Time.now - 1
722
+ ----
723
+
724
+ ==== String
683
725
 
684
726
  ===== #blank?
685
727
 
@@ -690,13 +732,13 @@ Answers `true`/`false` based on whether string is blank, `<space>`, `\n`, `\t`,
690
732
  " \n\t\r".blank? # => true
691
733
  ----
692
734
 
693
- ===== #up
735
+ ===== #camelcase
694
736
 
695
- Answers string with only first letter upcased.
737
+ Answers a camelcased string.
696
738
 
697
739
  [source,ruby]
698
740
  ----
699
- "example".up # => "Example"
741
+ "this_is_an_example".camelcase # => "ThisIsAnExample"
700
742
  ----
701
743
 
702
744
  ===== #down
@@ -708,6 +750,16 @@ Answers string with only first letter downcased.
708
750
  "EXAMPLE".down # => "eXAMPLE"
709
751
  ----
710
752
 
753
+ ===== #first
754
+
755
+ Answers first character of a string or first set of characters if given a number.
756
+
757
+ [source,ruby]
758
+ ----
759
+ "example".first # => "e"
760
+ "example".first 4 # => "exam"
761
+ ----
762
+
711
763
  ===== #indent
712
764
 
713
765
  Answers string indented by two spaces by default.
@@ -721,13 +773,14 @@ Answers string indented by two spaces by default.
721
773
  "example".indent 3, padding: " " # => " example"
722
774
  ----
723
775
 
724
- ===== #camelcase
776
+ ===== #last
725
777
 
726
- Answers a camelcased string.
778
+ Answers last character of a string or last set of characters if given a number.
727
779
 
728
780
  [source,ruby]
729
781
  ----
730
- "this_is_an_example".camelcase # => "ThisIsAnExample"
782
+ "instant".last # => "t"
783
+ "instant".last 3 # => "ant"
731
784
  ----
732
785
 
733
786
  ===== #snakecase
@@ -761,6 +814,15 @@ Answers string as a boolean.
761
814
  "example".to_bool # => false
762
815
  ----
763
816
 
817
+ ===== #up
818
+
819
+ Answers string with only first letter upcased.
820
+
821
+ [source,ruby]
822
+ ----
823
+ "example".up # => "Example"
824
+ ----
825
+
764
826
  ==== String IO
765
827
 
766
828
  ===== #reread
@@ -11,6 +11,10 @@ module Refinements
11
11
  replace compress
12
12
  end
13
13
 
14
+ def exclude *elements
15
+ self - elements.flatten
16
+ end
17
+
14
18
  def include *elements
15
19
  self + elements.flatten
16
20
  end
@@ -19,10 +23,6 @@ module Refinements
19
23
  product([elements]).tap(&:pop).flatten.push last
20
24
  end
21
25
 
22
- def exclude *elements
23
- self - elements.flatten
24
- end
25
-
26
26
  def mean
27
27
  size.zero? ? 0 : sum(0) / size
28
28
  end
@@ -13,49 +13,6 @@ module Refinements
13
13
  end
14
14
 
15
15
  refine Hash do
16
- def except *keys
17
- reject { |key, _value| keys.include? key }
18
- end
19
-
20
- def except! *keys
21
- replace except(*keys)
22
- end
23
-
24
- # :reek:TooManyStatements
25
- def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
26
- fail StandardError, "Unknown cast: #{cast}." unless %i[to_sym to_s].include? cast
27
-
28
- reduce({}) do |flat, (key, value)|
29
- flat_key = prefix ? "#{prefix}#{delimiter}#{key}" : key
30
-
31
- next flat.merge flat_key.public_send(cast) => value unless value.is_a? self.class
32
-
33
- flat.merge(
34
- recurse { value.flatten_keys prefix: flat_key, delimiter: delimiter, cast: cast }
35
- )
36
- end
37
- end
38
-
39
- def flatten_keys! prefix: nil, delimiter: "_", cast: :to_sym
40
- replace flatten_keys(prefix: prefix, delimiter: delimiter, cast: cast)
41
- end
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
-
51
- def symbolize_keys
52
- reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
53
- end
54
-
55
- def symbolize_keys!
56
- replace symbolize_keys
57
- end
58
-
59
16
  def deep_merge other
60
17
  clazz = self.class
61
18
 
@@ -88,6 +45,33 @@ module Refinements
88
45
  replace deep_symbolize_keys
89
46
  end
90
47
 
48
+ def except *keys
49
+ reject { |key, _value| keys.include? key }
50
+ end
51
+
52
+ def except! *keys
53
+ replace except(*keys)
54
+ end
55
+
56
+ # :reek:TooManyStatements
57
+ def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
58
+ fail StandardError, "Unknown cast: #{cast}." unless %i[to_sym to_s].include? cast
59
+
60
+ reduce({}) do |flat, (key, value)|
61
+ flat_key = prefix ? "#{prefix}#{delimiter}#{key}" : key
62
+
63
+ next flat.merge flat_key.public_send(cast) => value unless value.is_a? self.class
64
+
65
+ flat.merge(
66
+ recurse { value.flatten_keys prefix: flat_key, delimiter: delimiter, cast: cast }
67
+ )
68
+ end
69
+ end
70
+
71
+ def flatten_keys! prefix: nil, delimiter: "_", cast: :to_sym
72
+ replace flatten_keys(prefix: prefix, delimiter: delimiter, cast: cast)
73
+ end
74
+
91
75
  def recurse &block
92
76
  return self unless block_given?
93
77
 
@@ -118,6 +102,22 @@ module Refinements
118
102
  replace reverse_merge(other)
119
103
  end
120
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
120
+
121
121
  def use &block
122
122
  return [] unless block_given?
123
123
 
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.12.0"
8
+ VERSION = "7.13.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -14,10 +14,6 @@ module Refinements
14
14
  end
15
15
 
16
16
  refine IO do
17
- def squelch &block
18
- self.class.void.then { |void| redirect(void, &block) }
19
- end
20
-
21
17
  def redirect other
22
18
  return self unless block_given?
23
19
 
@@ -30,6 +26,10 @@ module Refinements
30
26
  def reread length = nil, buffer: nil
31
27
  tap(&:rewind).read length, buffer
32
28
  end
29
+
30
+ def squelch &block
31
+ self.class.void.then { |void| redirect(void, &block) }
32
+ end
33
33
  end
34
34
  end
35
35
  end
@@ -13,8 +13,9 @@ module Refinements
13
13
  end
14
14
 
15
15
  refine Pathname do
16
- def name
17
- basename extname
16
+ def change_dir &block
17
+ Dir.chdir(self, &block)
18
+ self
18
19
  end
19
20
 
20
21
  def copy to
@@ -39,6 +40,28 @@ module Refinements
39
40
  self.class.new to_s.gsub(pattern, replacement)
40
41
  end
41
42
 
43
+ def make_ancestors
44
+ dirname.mkpath
45
+ self
46
+ end
47
+
48
+ def make_dir
49
+ exist? ? self : mkdir and self
50
+ end
51
+
52
+ def make_path
53
+ mkpath
54
+ self
55
+ end
56
+
57
+ def mkdir
58
+ exist? ? self : super and self
59
+ end
60
+
61
+ def name
62
+ basename extname
63
+ end
64
+
42
65
  def relative_parent root_dir
43
66
  relative_path_from(root_dir).parent
44
67
  end
@@ -49,16 +72,14 @@ module Refinements
49
72
  relative_parent root_dir
50
73
  end
51
74
 
52
- def make_ancestors
53
- dirname.mkpath
54
- self
75
+ def remove_dir
76
+ exist? ? (rmdir and self) : self
55
77
  end
56
78
 
57
- # rubocop:disable Style/RedundantSelf
58
- def mkdir
59
- self.exist? ? self : super and self
79
+ def remove_tree
80
+ rmtree if exist?
81
+ self
60
82
  end
61
- # rubocop:enable Style/RedundantSelf
62
83
 
63
84
  def rewrite
64
85
  read.then { |content| write yield(content) if block_given? }
@@ -12,42 +12,33 @@ module Refinements
12
12
  end
13
13
 
14
14
  refine String do
15
- def first number = 0
16
- return self if empty?
17
-
18
- max = Integer number
15
+ def blank?
16
+ match?(/\A\s*\z/)
17
+ end
19
18
 
20
- return self[0] if max.zero?
21
- return "" if max.negative?
19
+ def camelcase
20
+ return up unless match? DELIMITERS
22
21
 
23
- self[..(max - 1)]
22
+ split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :up, "::" }
23
+ .then { |text| text.split(/\s*_\s*|\s+/) }
24
+ .then { |parts| combine parts, :up }
24
25
  end
25
26
 
26
- def last number = 0
27
+ def down
27
28
  return self if empty?
28
29
 
29
- min = Integer number
30
-
31
- return self[size - 1] if min.zero?
32
- return "" if min.negative?
33
-
34
- self[(min + 1)..]
35
- end
36
-
37
- def blank?
38
- match?(/\A\s*\z/)
30
+ first.downcase + self[1, size]
39
31
  end
40
32
 
41
- def up
33
+ def first number = 0
42
34
  return self if empty?
43
35
 
44
- first.upcase + self[1, size]
45
- end
36
+ max = Integer number
46
37
 
47
- def down
48
- return self if empty?
38
+ return self[0] if max.zero?
39
+ return "" if max.negative?
49
40
 
50
- first.downcase + self[1, size]
41
+ self[..(max - 1)]
51
42
  end
52
43
 
53
44
  def indent multiplier = 1, padding: " "
@@ -56,12 +47,15 @@ module Refinements
56
47
  padding * multiplier + self
57
48
  end
58
49
 
59
- def camelcase
60
- return up unless match? DELIMITERS
50
+ def last number = 0
51
+ return self if empty?
61
52
 
62
- split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :up, "::" }
63
- .then { |text| text.split(/\s*_\s*|\s+/) }
64
- .then { |parts| combine parts, :up }
53
+ min = Integer number
54
+
55
+ return self[size - 1] if min.zero?
56
+ return "" if min.negative?
57
+
58
+ self[(min + 1)..]
65
59
  end
66
60
 
67
61
  def snakecase
@@ -84,6 +78,12 @@ module Refinements
84
78
  %w[true yes on t y 1].include? downcase.strip
85
79
  end
86
80
 
81
+ def up
82
+ return self if empty?
83
+
84
+ first.upcase + self[1, size]
85
+ end
86
+
87
87
  private
88
88
 
89
89
  # :reek:DuplicateMethodCall
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.12.0
4
+ version: 7.13.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-11-04 00:00:00.000000000 Z
31
+ date: 2020-11-07 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