refinements 7.15.1 → 8.0.1
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.tar.gz.sig +0 -0
- data/README.adoc +176 -85
- data/lib/refinements.rb +0 -1
- data/lib/refinements/arrays.rb +4 -10
- data/lib/refinements/hashes.rb +0 -28
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/pathnames.rb +19 -5
- data/lib/refinements/strings.rb +1 -8
- data/lib/refinements/structs.rb +31 -2
- metadata +5 -216
- 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: aa3c406709e8a34ba5de77de6416ba4a180a42dc994252fb35b9414a73d941c2
|
4
|
+
data.tar.gz: 99426faa5a56f5352ed5620fe4a94e090121c7bd7555ad3c15d0b3a8beee65a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeb946bc0824dd153fd3bb4615287b0e088c10693c45bdc728e2ee4f2f75207f079584d357afd3085ff289b3cbae45f1f5e14aeb099c0170e78adc0b6012a6bb
|
7
|
+
data.tar.gz: 2fbe37e1cbc1f8c4cc966f7f3d7db70a74481481ecc4c5770053d2b156dfc681e6fd8b2ab1f4432d87daa719a9c6962dd8354a42011ccce61ed7c40d29768d25
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
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
|
@@ -171,6 +168,18 @@ Answers mean/average all elements within an array.
|
|
171
168
|
[1.25, 1.5, 1.75].mean # => 1.5
|
172
169
|
----
|
173
170
|
|
171
|
+
===== #pad
|
172
|
+
|
173
|
+
Answers new array padded with given value up to a maximum size. Useful in situations where an array
|
174
|
+
needs to be a specific size with padded values.
|
175
|
+
|
176
|
+
[source,ruby]
|
177
|
+
----
|
178
|
+
[1].pad 0 # => [1]
|
179
|
+
[1].pad 0, max: 3 # => [1, 0, 0]
|
180
|
+
[1, 2].pad 3, max: 3 # => [1, 2, 3]
|
181
|
+
----
|
182
|
+
|
174
183
|
===== #ring
|
175
184
|
|
176
185
|
Answers a circular array which can enumerate before, current, after elements.
|
@@ -208,18 +217,6 @@ Answers new DateTime object for current UTC date/time.
|
|
208
217
|
DateTime.utc # => #<DateTime: 2019-12-31T18:17:00+00:00 ((2458849j,65820s,181867000n),+0s,2299161j)>
|
209
218
|
----
|
210
219
|
|
211
|
-
==== File
|
212
|
-
|
213
|
-
===== .rewrite
|
214
|
-
|
215
|
-
When given a file path and a block, it provides the contents of the recently read file for
|
216
|
-
manipulation and immediate writing back to the same file.
|
217
|
-
|
218
|
-
[source,ruby]
|
219
|
-
----
|
220
|
-
File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
|
221
|
-
----
|
222
|
-
|
223
220
|
==== Hash
|
224
221
|
|
225
222
|
===== .infinite
|
@@ -312,28 +309,6 @@ example.deep_symbolize_keys! # => {a: {b: 1}}
|
|
312
309
|
example # => {a: {b: 1}}
|
313
310
|
----
|
314
311
|
|
315
|
-
===== #except
|
316
|
-
|
317
|
-
Answers new hash with given keys removed without mutating itself.
|
318
|
-
|
319
|
-
[source,ruby]
|
320
|
-
----
|
321
|
-
example = {a: 1, b: 2, c: 3}
|
322
|
-
example.except :a, :b # => {c: 3}
|
323
|
-
example # => {a: 1, b: 2, c: 3}
|
324
|
-
----
|
325
|
-
|
326
|
-
===== #except!
|
327
|
-
|
328
|
-
Answers new hash with given keys removed while mutating itself.
|
329
|
-
|
330
|
-
[source,ruby]
|
331
|
-
----
|
332
|
-
example = {a: 1, b: 2, c: 3}
|
333
|
-
example.except! :a, :b # => {c: 3}
|
334
|
-
example # => {c: 3}
|
335
|
-
----
|
336
|
-
|
337
312
|
===== #flatten_keys
|
338
313
|
|
339
314
|
Flattens nested keys as top-level keys without mutating itself. Does not handle nested arrays,
|
@@ -376,50 +351,6 @@ example.recurse(&:symbolize_keys) # => {a: {b: 1}}
|
|
376
351
|
example.recurse(&:invert) # => {{"b" => 1} => "a"}
|
377
352
|
----
|
378
353
|
|
379
|
-
===== #rekey
|
380
|
-
|
381
|
-
Transforms keys per mapping (size of mapping can vary) without mutating itself.
|
382
|
-
|
383
|
-
[source,ruby]
|
384
|
-
----
|
385
|
-
example = {a: 1, b: 2, c: 3}
|
386
|
-
example.rekey a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
|
387
|
-
example # => {a: 1, b: 2, c: 3}
|
388
|
-
----
|
389
|
-
|
390
|
-
===== #rekey!
|
391
|
-
|
392
|
-
Transforms keys per mapping (size of mapping can vary) while mutating itself.
|
393
|
-
|
394
|
-
[source,ruby]
|
395
|
-
----
|
396
|
-
example = {a: 1, b: 2, c: 3}
|
397
|
-
example.rekey! a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
|
398
|
-
example # => {amber: 1, blue: 2, c: 3}
|
399
|
-
----
|
400
|
-
|
401
|
-
===== #reverse_merge
|
402
|
-
|
403
|
-
Merges calling hash into passed in hash without mutating itself.
|
404
|
-
|
405
|
-
[source,ruby]
|
406
|
-
----
|
407
|
-
example = {a: 1, b: 2}
|
408
|
-
example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
409
|
-
example # => {a: 1, b: 2}
|
410
|
-
----
|
411
|
-
|
412
|
-
===== #reverse_merge!
|
413
|
-
|
414
|
-
Merges calling hash into passed in hash while mutating itself.
|
415
|
-
|
416
|
-
[source,ruby]
|
417
|
-
----
|
418
|
-
example = {a: 1, b: 2}
|
419
|
-
example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
420
|
-
example # => {a: 1, b: 2, c: 3}
|
421
|
-
----
|
422
|
-
|
423
354
|
===== #stringify_keys
|
424
355
|
|
425
356
|
Converts keys to strings without mutating itself.
|
@@ -546,10 +477,79 @@ construct a valid path.
|
|
546
477
|
Pathname(nil) # => Pathname("")
|
547
478
|
----
|
548
479
|
|
480
|
+
===== .home
|
481
|
+
|
482
|
+
Answers user home directory.
|
483
|
+
|
484
|
+
[source,ruby]
|
485
|
+
----
|
486
|
+
Pathname.home # => Pathname "/Users/bkuhlmann"
|
487
|
+
----
|
488
|
+
|
489
|
+
===== .make_temp_dir
|
490
|
+
|
491
|
+
Wraps `Dir.mktmpdir` with the following behavior (see
|
492
|
+
link:https://rubyapi.org/o/Dir.mktmpdir#method-c-mktmpdir[Dir.mktmpdir] for details):
|
493
|
+
|
494
|
+
* *Without Block* - Answers a newly created Pathname instance which is not automatically cleaned up.
|
495
|
+
* *With Block* Yields a Pathname instance, answers result of given block, and automatidally cleans
|
496
|
+
up temporary directory after block exits.
|
497
|
+
|
498
|
+
The following examples use truncated temporary directories for illustration purposes only. In
|
499
|
+
reality, these paths will be longer depending on which operating system you are using.
|
500
|
+
|
501
|
+
[source,ruby]
|
502
|
+
----
|
503
|
+
Pathname.make_temp_dir # => Pathname:/var/folders/T/temp-20200101-16940-r8
|
504
|
+
Pathname.make_temp_dir prefix: "prefix-" # => Pathname:/var/folders/T/prefix-20200101-16940-r8
|
505
|
+
Pathname.make_temp_dir suffix: "-suffix" # => Pathname:/var/folders/T/temp-20200101-16940-r8-suffix
|
506
|
+
Pathname.make_temp_dir prefix: "prefix-", suffix: "-suffix" # => Pathname:/var/folders/T/prefix-20200101-16940-r8-suffix
|
507
|
+
Pathname.make_temp_dir root: "/example" # => Pathname:/example/temp-20200101-16940-r8
|
508
|
+
Pathname.make_temp_dir { "I am a block result" } # => "I am a block result"
|
509
|
+
Pathname.make_temp_dir { |path| path.join "sub_dir" } # => Pathname:/var/folders/T/temp-20200101-16940-r8/sub_dir
|
510
|
+
----
|
511
|
+
|
512
|
+
===== .require_tree
|
513
|
+
|
514
|
+
Requires all files in given root path and corresponding nested tree structure. All files are sorted
|
515
|
+
before being required to ensure consistent behavior. Example:
|
516
|
+
|
517
|
+
[source,ruby]
|
518
|
+
----
|
519
|
+
# Before
|
520
|
+
Dir[File.join(__dir__, "support/shared_contexts/**/*.rb")].sort.each { |path| require path }
|
521
|
+
|
522
|
+
# After
|
523
|
+
Pathname.require_tree __dir__, "support/shared_contexts/**/*.rb"
|
524
|
+
----
|
525
|
+
|
526
|
+
The following are further examples of potential usage:
|
527
|
+
|
528
|
+
[source,ruby]
|
529
|
+
----
|
530
|
+
# Requires all files in root directory and below.
|
531
|
+
Pathname.require_tree __dir__
|
532
|
+
|
533
|
+
# Requires all files in `/test/**/*.rb` and below.
|
534
|
+
Pathname.require_tree "/test"
|
535
|
+
|
536
|
+
# Requires all files in RSpec shared examples directory structure.
|
537
|
+
Pathname.require_tree Bundler.root.join("spec"), "support/shared_examples/**/*.rb"
|
538
|
+
----
|
539
|
+
|
540
|
+
===== .root
|
541
|
+
|
542
|
+
Answers operating system root path.
|
543
|
+
|
544
|
+
[source,ruby]
|
545
|
+
----
|
546
|
+
Pathname.root # => Pathname "/"
|
547
|
+
----
|
548
|
+
|
549
549
|
===== #change_dir
|
550
550
|
|
551
|
-
|
552
|
-
link:https://rubyapi.org/
|
551
|
+
Wraps `Dir.chdir` behavior by changing to directory of current path. See
|
552
|
+
link:https://rubyapi.org/o/Dir.chdir#method-c-chdir[Dir.chdir] for details.
|
553
553
|
|
554
554
|
[source,ruby]
|
555
555
|
----
|
@@ -716,8 +716,8 @@ Updates access and modification times for path. Defaults to current time.
|
|
716
716
|
|
717
717
|
[source,ruby]
|
718
718
|
----
|
719
|
-
Pathname("example.txt").touch
|
720
|
-
Pathname("example.txt").touch
|
719
|
+
Pathname("example.txt").touch # => Pathname("example.txt")
|
720
|
+
Pathname("example.txt").touch Time.now - 1 # => Pathname("example.txt")
|
721
721
|
----
|
722
722
|
|
723
723
|
===== #write
|
@@ -855,6 +855,50 @@ buffer # => "This is a test."
|
|
855
855
|
|
856
856
|
==== Struct
|
857
857
|
|
858
|
+
===== .keyworded?
|
859
|
+
|
860
|
+
Answers whether a struct was constructed with keyword or positional arguments.
|
861
|
+
|
862
|
+
[source,ruby]
|
863
|
+
----
|
864
|
+
Struct.new(:a, keyword_init: true).keyworded? # => true
|
865
|
+
Struct.new(:a).keyworded? # => false
|
866
|
+
----
|
867
|
+
|
868
|
+
===== .with_keywords
|
869
|
+
|
870
|
+
Answers a struct instance with given keyword arguments regardless of
|
871
|
+
whether the struct was constructed with positional or keyword arguments.
|
872
|
+
|
873
|
+
[source,ruby]
|
874
|
+
----
|
875
|
+
Example = Struct.new :a, :b, :c
|
876
|
+
Example.with_keywords a: 1, b: 2, c: 3 # => #<struct a=1, b=2, c=3>
|
877
|
+
Example.with_keywords a: 1 # => #<struct a=1, b=nil, c=nil>
|
878
|
+
Example.with_keywords c: 1 # => #<struct a=nil, b=nil, c=1>
|
879
|
+
|
880
|
+
Example = Struct.new :a, :b, :c, keyword_init: true
|
881
|
+
Example.with_keywords a: 1, b: 2, c: 3 # => #<struct a=1, b=2, c=3>
|
882
|
+
Example.with_keywords a: 1 # => #<struct a=1, b=nil, c=nil>
|
883
|
+
Example.with_keywords c: 1 # => #<struct a=nil, b=nil, c=1>
|
884
|
+
----
|
885
|
+
|
886
|
+
===== .with_positions
|
887
|
+
|
888
|
+
Answers a struct instance with given positional arguments regardless of
|
889
|
+
whether the struct was constructed with positional or keyword arguments.
|
890
|
+
|
891
|
+
[source,ruby]
|
892
|
+
----
|
893
|
+
Example = Struct.new :a, :b, :c
|
894
|
+
Example.with_positions 1, 2, 3 # => #<struct a=1, b=2, c=3>
|
895
|
+
Example.with_positions 1 # => #<struct a=1, b=nil, c=nil>
|
896
|
+
|
897
|
+
Example = Struct.new :a, :b, :c, keyword_init: true
|
898
|
+
Example.with_positions 1, 2, 3 # => #<struct a=1, b=2, c=3>
|
899
|
+
Example.with_positions 1 # => #<struct a=1, b=nil, c=nil>
|
900
|
+
----
|
901
|
+
|
858
902
|
===== #merge
|
859
903
|
|
860
904
|
Merges multiple attributes without mutating itself.
|
@@ -897,6 +941,53 @@ example.merge! a: 10, b: 20, c: 30 # => #<struct a=10, b=20, c=30>
|
|
897
941
|
example # => #<struct a=10, b=20, c=30>
|
898
942
|
----
|
899
943
|
|
944
|
+
===== #revalue
|
945
|
+
|
946
|
+
Transforms values without mutating itself. An optional hash can be supplied to pinpoint and
|
947
|
+
transform specific attributes. In the event that a block isn't supplied, the struct will answer
|
948
|
+
itself since there is nothing to operate on. Behavior is the same regardless of whether the struct
|
949
|
+
is constructed using positional or keyword arguments. A positional struct is used in the examples
|
950
|
+
below but a keyword struct would work too.
|
951
|
+
|
952
|
+
[source,ruby]
|
953
|
+
----
|
954
|
+
Example = Struct.new :a, :b, :c
|
955
|
+
|
956
|
+
example = Example[1, 2, 3]
|
957
|
+
example.revalue { |value| value * 2 } # => #<struct a=2, b=4, c=6>
|
958
|
+
example.revalue(c: 2) { |previous, current| previous + current } # => #<struct a=1, b=2, c=5>
|
959
|
+
example.revalue c: 2 # => #<struct a=1, b=2, c=3>
|
960
|
+
example.revalue # => #<struct a=1, b=2, c=3>
|
961
|
+
example # => #<struct a=1, b=2, c=3>
|
962
|
+
|
963
|
+
----
|
964
|
+
|
965
|
+
===== #revalue!
|
966
|
+
|
967
|
+
Transforms values while mutating itself. An optional hash can be supplied to pinpoint and transform
|
968
|
+
specific attributes. In the event that a block isn't supplied, the struct will answer itself since
|
969
|
+
there is nothing to operate on. Behavior is the same regardless of whether the struct is constructed
|
970
|
+
using positional or keyword arguments. A positional struct is used in the examples below but a
|
971
|
+
keyword struct would work too.
|
972
|
+
|
973
|
+
[source,ruby]
|
974
|
+
----
|
975
|
+
Example = Struct.new :a, :b, :c
|
976
|
+
|
977
|
+
example = Example[1, 2, 3]
|
978
|
+
example.revalue! { |value| value * 2 } # => #<struct a=2, b=4, c=6>
|
979
|
+
example # => #<struct a=2, b=4, c=6>
|
980
|
+
|
981
|
+
example = Example[1, 2, 3]
|
982
|
+
example.revalue!(c: 2) { |previous, current| previous + current } # => #<struct a=1, b=2, c=5>
|
983
|
+
example # => #<struct a=1, b=2, c=5>
|
984
|
+
|
985
|
+
example = Example[1, 2, 3]
|
986
|
+
example.revalue! c: 2 # => #<struct a=1, b=2, c=3>
|
987
|
+
example.revalue! # => #<struct a=1, b=2, c=3>
|
988
|
+
example # => #<struct a=1, b=2, c=3>
|
989
|
+
----
|
990
|
+
|
900
991
|
== Development
|
901
992
|
|
902
993
|
To contribute, run:
|
data/lib/refinements.rb
CHANGED
data/lib/refinements/arrays.rb
CHANGED
@@ -11,20 +11,10 @@ module Refinements
|
|
11
11
|
replace compress
|
12
12
|
end
|
13
13
|
|
14
|
-
def exclude *elements
|
15
|
-
warn "[DEPRECATION]: #exclude is deprecated, use #excluding instead."
|
16
|
-
excluding(*elements)
|
17
|
-
end
|
18
|
-
|
19
14
|
def excluding *elements
|
20
15
|
self - elements.flatten
|
21
16
|
end
|
22
17
|
|
23
|
-
def include *elements
|
24
|
-
warn "[DEPRECATION]: #include is deprecated, use #including instead."
|
25
|
-
including(*elements)
|
26
|
-
end
|
27
|
-
|
28
18
|
def including *elements
|
29
19
|
self + elements.flatten
|
30
20
|
end
|
@@ -37,6 +27,10 @@ module Refinements
|
|
37
27
|
size.zero? ? 0 : sum(0) / size
|
38
28
|
end
|
39
29
|
|
30
|
+
def pad value, max: size
|
31
|
+
dup.fill value, size..(max - 1)
|
32
|
+
end
|
33
|
+
|
40
34
|
def ring &block
|
41
35
|
[last, *self, first].each_cons 3, &block
|
42
36
|
end
|
data/lib/refinements/hashes.rb
CHANGED
@@ -45,14 +45,6 @@ module Refinements
|
|
45
45
|
replace deep_symbolize_keys
|
46
46
|
end
|
47
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
48
|
# :reek:TooManyStatements
|
57
49
|
def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
|
58
50
|
fail StandardError, "Unknown cast: #{cast}." unless %i[to_sym to_s].include? cast
|
@@ -82,26 +74,6 @@ module Refinements
|
|
82
74
|
end
|
83
75
|
end
|
84
76
|
|
85
|
-
def rekey mapping = {}
|
86
|
-
return self if mapping.empty?
|
87
|
-
|
88
|
-
transform_keys { |key| mapping[key] || key }
|
89
|
-
end
|
90
|
-
|
91
|
-
def rekey! mapping = {}
|
92
|
-
replace rekey(mapping)
|
93
|
-
end
|
94
|
-
|
95
|
-
def reverse_merge other
|
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
77
|
def stringify_keys
|
106
78
|
reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
107
79
|
end
|
data/lib/refinements/identity.rb
CHANGED
@@ -12,6 +12,24 @@ module Refinements
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
refine Pathname.singleton_class do
|
16
|
+
def home
|
17
|
+
new ENV["HOME"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def make_temp_dir prefix: "temp-", suffix: nil, root: nil
|
21
|
+
Dir.mktmpdir([prefix, suffix], root) { |path| block_given? ? yield(new path) : new(path) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def require_tree root, pattern = "**/*.rb"
|
25
|
+
new(root).files(pattern).each { |path| require path.to_s }
|
26
|
+
end
|
27
|
+
|
28
|
+
def root
|
29
|
+
new "/"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
15
33
|
refine Pathname do
|
16
34
|
def change_dir &block
|
17
35
|
block ? Dir.chdir(self, &block) : (Dir.chdir self and self)
|
@@ -53,10 +71,6 @@ module Refinements
|
|
53
71
|
self
|
54
72
|
end
|
55
73
|
|
56
|
-
def mkdir
|
57
|
-
exist? ? self : super and self
|
58
|
-
end
|
59
|
-
|
60
74
|
def name
|
61
75
|
basename extname
|
62
76
|
end
|
@@ -84,7 +98,7 @@ module Refinements
|
|
84
98
|
read.then { |content| write yield(content) if block_given? }
|
85
99
|
end
|
86
100
|
|
87
|
-
def touch at
|
101
|
+
def touch at = Time.now
|
88
102
|
exist? ? utime(at, at) : write("")
|
89
103
|
self
|
90
104
|
end
|
data/lib/refinements/strings.rb
CHANGED
@@ -2,14 +2,7 @@
|
|
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
8
|
def blank?
|
data/lib/refinements/structs.rb
CHANGED
@@ -2,13 +2,42 @@
|
|
2
2
|
|
3
3
|
module Refinements
|
4
4
|
module Structs
|
5
|
+
refine Struct.singleton_class do
|
6
|
+
def keyworded?
|
7
|
+
inspect.include? "keyword_init: true"
|
8
|
+
end
|
9
|
+
|
10
|
+
def with_keywords **arguments
|
11
|
+
keyworded? ? new(**arguments) : new.merge!(**arguments)
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_positions *values
|
15
|
+
keyworded? ? new(**Hash[members.zip values]) : new(*values)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
refine Struct do
|
6
20
|
def merge **attributes
|
7
|
-
dup.merge!
|
21
|
+
dup.merge!(**attributes)
|
8
22
|
end
|
9
23
|
|
10
24
|
def merge! **attributes
|
11
|
-
to_h.merge(attributes).each { |key, value| self[key] = value }
|
25
|
+
to_h.merge(**attributes).each { |key, value| self[key] = value }
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def revalue attributes = each_pair
|
30
|
+
return self unless block_given?
|
31
|
+
|
32
|
+
dup.tap do |copy|
|
33
|
+
attributes.each { |key, value| copy[key] = yield self[key], value }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def revalue! attributes = each_pair
|
38
|
+
return self unless block_given?
|
39
|
+
|
40
|
+
attributes.each { |key, value| self[key] = yield self[key], value }
|
12
41
|
self
|
13
42
|
end
|
14
43
|
end
|
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.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -28,218 +28,8 @@ cert_chain:
|
|
28
28
|
2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
|
29
29
|
QWc=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2020-
|
32
|
-
dependencies:
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: bundler-audit
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '0.7'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0.7'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: bundler-leak
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.2'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0.2'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: gemsmith
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - "~>"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '14.8'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '14.8'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: git-lint
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - "~>"
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '1.3'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - "~>"
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '1.3'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: guard-rspec
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '4.7'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '4.7'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: pry
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0.13'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '0.13'
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
|
-
name: pry-byebug
|
119
|
-
requirement: !ruby/object:Gem::Requirement
|
120
|
-
requirements:
|
121
|
-
- - "~>"
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: '3.9'
|
124
|
-
type: :development
|
125
|
-
prerelease: false
|
126
|
-
version_requirements: !ruby/object:Gem::Requirement
|
127
|
-
requirements:
|
128
|
-
- - "~>"
|
129
|
-
- !ruby/object:Gem::Version
|
130
|
-
version: '3.9'
|
131
|
-
- !ruby/object:Gem::Dependency
|
132
|
-
name: rake
|
133
|
-
requirement: !ruby/object:Gem::Requirement
|
134
|
-
requirements:
|
135
|
-
- - "~>"
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
version: '13.0'
|
138
|
-
type: :development
|
139
|
-
prerelease: false
|
140
|
-
version_requirements: !ruby/object:Gem::Requirement
|
141
|
-
requirements:
|
142
|
-
- - "~>"
|
143
|
-
- !ruby/object:Gem::Version
|
144
|
-
version: '13.0'
|
145
|
-
- !ruby/object:Gem::Dependency
|
146
|
-
name: reek
|
147
|
-
requirement: !ruby/object:Gem::Requirement
|
148
|
-
requirements:
|
149
|
-
- - "~>"
|
150
|
-
- !ruby/object:Gem::Version
|
151
|
-
version: '6.0'
|
152
|
-
type: :development
|
153
|
-
prerelease: false
|
154
|
-
version_requirements: !ruby/object:Gem::Requirement
|
155
|
-
requirements:
|
156
|
-
- - "~>"
|
157
|
-
- !ruby/object:Gem::Version
|
158
|
-
version: '6.0'
|
159
|
-
- !ruby/object:Gem::Dependency
|
160
|
-
name: rspec
|
161
|
-
requirement: !ruby/object:Gem::Requirement
|
162
|
-
requirements:
|
163
|
-
- - "~>"
|
164
|
-
- !ruby/object:Gem::Version
|
165
|
-
version: '3.10'
|
166
|
-
type: :development
|
167
|
-
prerelease: false
|
168
|
-
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
requirements:
|
170
|
-
- - "~>"
|
171
|
-
- !ruby/object:Gem::Version
|
172
|
-
version: '3.10'
|
173
|
-
- !ruby/object:Gem::Dependency
|
174
|
-
name: rubocop
|
175
|
-
requirement: !ruby/object:Gem::Requirement
|
176
|
-
requirements:
|
177
|
-
- - "~>"
|
178
|
-
- !ruby/object:Gem::Version
|
179
|
-
version: '1.3'
|
180
|
-
type: :development
|
181
|
-
prerelease: false
|
182
|
-
version_requirements: !ruby/object:Gem::Requirement
|
183
|
-
requirements:
|
184
|
-
- - "~>"
|
185
|
-
- !ruby/object:Gem::Version
|
186
|
-
version: '1.3'
|
187
|
-
- !ruby/object:Gem::Dependency
|
188
|
-
name: rubocop-performance
|
189
|
-
requirement: !ruby/object:Gem::Requirement
|
190
|
-
requirements:
|
191
|
-
- - "~>"
|
192
|
-
- !ruby/object:Gem::Version
|
193
|
-
version: '1.8'
|
194
|
-
type: :development
|
195
|
-
prerelease: false
|
196
|
-
version_requirements: !ruby/object:Gem::Requirement
|
197
|
-
requirements:
|
198
|
-
- - "~>"
|
199
|
-
- !ruby/object:Gem::Version
|
200
|
-
version: '1.8'
|
201
|
-
- !ruby/object:Gem::Dependency
|
202
|
-
name: rubocop-rake
|
203
|
-
requirement: !ruby/object:Gem::Requirement
|
204
|
-
requirements:
|
205
|
-
- - "~>"
|
206
|
-
- !ruby/object:Gem::Version
|
207
|
-
version: '0.5'
|
208
|
-
type: :development
|
209
|
-
prerelease: false
|
210
|
-
version_requirements: !ruby/object:Gem::Requirement
|
211
|
-
requirements:
|
212
|
-
- - "~>"
|
213
|
-
- !ruby/object:Gem::Version
|
214
|
-
version: '0.5'
|
215
|
-
- !ruby/object:Gem::Dependency
|
216
|
-
name: rubocop-rspec
|
217
|
-
requirement: !ruby/object:Gem::Requirement
|
218
|
-
requirements:
|
219
|
-
- - "~>"
|
220
|
-
- !ruby/object:Gem::Version
|
221
|
-
version: '2.0'
|
222
|
-
type: :development
|
223
|
-
prerelease: false
|
224
|
-
version_requirements: !ruby/object:Gem::Requirement
|
225
|
-
requirements:
|
226
|
-
- - "~>"
|
227
|
-
- !ruby/object:Gem::Version
|
228
|
-
version: '2.0'
|
229
|
-
- !ruby/object:Gem::Dependency
|
230
|
-
name: simplecov
|
231
|
-
requirement: !ruby/object:Gem::Requirement
|
232
|
-
requirements:
|
233
|
-
- - "~>"
|
234
|
-
- !ruby/object:Gem::Version
|
235
|
-
version: '0.19'
|
236
|
-
type: :development
|
237
|
-
prerelease: false
|
238
|
-
version_requirements: !ruby/object:Gem::Requirement
|
239
|
-
requirements:
|
240
|
-
- - "~>"
|
241
|
-
- !ruby/object:Gem::Version
|
242
|
-
version: '0.19'
|
31
|
+
date: 2020-12-29 00:00:00.000000000 Z
|
32
|
+
dependencies: []
|
243
33
|
description:
|
244
34
|
email:
|
245
35
|
- brooke@alchemists.io
|
@@ -255,7 +45,6 @@ files:
|
|
255
45
|
- lib/refinements/arrays.rb
|
256
46
|
- lib/refinements/big_decimals.rb
|
257
47
|
- lib/refinements/date_times.rb
|
258
|
-
- lib/refinements/files.rb
|
259
48
|
- lib/refinements/hashes.rb
|
260
49
|
- lib/refinements/identity.rb
|
261
50
|
- lib/refinements/ios.rb
|
@@ -279,14 +68,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
279
68
|
requirements:
|
280
69
|
- - "~>"
|
281
70
|
- !ruby/object:Gem::Version
|
282
|
-
version: '
|
71
|
+
version: '3.0'
|
283
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
284
73
|
requirements:
|
285
74
|
- - ">="
|
286
75
|
- !ruby/object:Gem::Version
|
287
76
|
version: '0'
|
288
77
|
requirements: []
|
289
|
-
rubygems_version: 3.
|
78
|
+
rubygems_version: 3.2.3
|
290
79
|
signing_key:
|
291
80
|
specification_version: 4
|
292
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
|