refinements 8.2.0 → 8.4.1
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/README.adoc +50 -9
- data/lib/refinements/arrays.rb +7 -3
- data/lib/refinements/big_decimals.rb +1 -0
- data/lib/refinements/date_times.rb +1 -0
- data/lib/refinements/hashes.rb +13 -4
- data/lib/refinements/identity.rb +2 -2
- data/lib/refinements/ios.rb +1 -0
- data/lib/refinements/pathnames.rb +4 -2
- data/lib/refinements/string_ios.rb +1 -0
- data/lib/refinements/strings.rb +3 -2
- data/lib/refinements/structs.rb +1 -0
- 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: 0b633f00ddb573cba22fcf647e293a7f4544fecc82ad3869d9c3528d0bd8e1aa
|
4
|
+
data.tar.gz: 00ef7df42687d801237b8b27563aaa028e19b75a4764c32a3c2220f58186dbe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb16cbce2ab22b6b95303751e87f09037dd570b38ffb7e6620d91a3e8e7bc9293fdcf4a4378e091847b12ccb80bd5d57c5bab22b0d930507327e54c29c9c855
|
7
|
+
data.tar.gz: 5767133f63df1a255b0ac9d6f9ff1ab6c8dfc73d237968a3cea225e3d2be4964fd8aa2298c7047cb81a8594ba6a9f4a676738d485519b696efeee20ddfe4b51d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -11,7 +11,9 @@ image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchem
|
|
11
11
|
[link=https://circleci.com/gh/bkuhlmann/refinements]
|
12
12
|
image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
|
13
13
|
|
14
|
-
|
14
|
+
Refinements is a collection of enhancements to primitive Ruby objects without needing to resort
|
15
|
+
painful and hard to debug monkey patches. These refinements give you additional syntactic sugar to
|
16
|
+
build clean and concise implementations all while using less code.
|
15
17
|
|
16
18
|
toc::[]
|
17
19
|
|
@@ -105,13 +107,14 @@ The following sections demonstrate how each refinement enriches your objects wit
|
|
105
107
|
|
106
108
|
===== #compress
|
107
109
|
|
108
|
-
Removes `nil` and empty
|
110
|
+
Removes `nil` and empty objects without mutating itself.
|
109
111
|
|
110
112
|
[source,ruby]
|
111
113
|
----
|
112
|
-
|
113
|
-
example
|
114
|
-
example
|
114
|
+
object = Object.new
|
115
|
+
example = [1, "blueberry", nil, "", [], {}, object]
|
116
|
+
example.compress # => [1, "blueberry", object]
|
117
|
+
example # => [1, "blueberry", nil, "", [], {}, object]
|
115
118
|
----
|
116
119
|
|
117
120
|
===== #compress!
|
@@ -120,9 +123,10 @@ Removes `nil` and empty values while mutating itself.
|
|
120
123
|
|
121
124
|
[source,ruby]
|
122
125
|
----
|
123
|
-
|
124
|
-
example
|
125
|
-
example
|
126
|
+
object = Object.new
|
127
|
+
example = [1, "blueberry", nil, "", [], {}, object]
|
128
|
+
example.compress # => [1, "blueberry", object]
|
129
|
+
example # => [1, "blueberry", object]
|
126
130
|
----
|
127
131
|
|
128
132
|
===== #excluding
|
@@ -286,6 +290,30 @@ example = Hash.with_default []
|
|
286
290
|
example[:b] # => []
|
287
291
|
----
|
288
292
|
|
293
|
+
===== #compress
|
294
|
+
|
295
|
+
Removes `nil` and empty objects without mutating itself.
|
296
|
+
|
297
|
+
[source,ruby]
|
298
|
+
----
|
299
|
+
object = Object.new
|
300
|
+
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
301
|
+
example.compress # => {a: 1, b: "blueberry", g: object}
|
302
|
+
example # => {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
303
|
+
----
|
304
|
+
|
305
|
+
===== #compress!
|
306
|
+
|
307
|
+
Removes `nil` and empty objects while mutating itself.
|
308
|
+
|
309
|
+
[source,ruby]
|
310
|
+
----
|
311
|
+
object = Object.new
|
312
|
+
example = {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: object}
|
313
|
+
example.compress! # => {a: 1, b: "blueberry", g: object}
|
314
|
+
example # => {a: 1, b: "blueberry", g: object}
|
315
|
+
----
|
316
|
+
|
289
317
|
===== #deep_merge
|
290
318
|
|
291
319
|
Merges deeply nested hashes together without mutating itself.
|
@@ -535,7 +563,7 @@ Wraps `Dir.mktmpdir` with the following behavior (see
|
|
535
563
|
link:https://rubyapi.org/o/Dir.mktmpdir#method-c-mktmpdir[Dir.mktmpdir] for details):
|
536
564
|
|
537
565
|
* *Without Block* - Answers a newly created Pathname instance which is not automatically cleaned up.
|
538
|
-
* *With Block* Yields a Pathname instance, answers result of given block, and
|
566
|
+
* *With Block* Yields a Pathname instance, answers result of given block, and automatically cleans
|
539
567
|
up temporary directory after block exits.
|
540
568
|
|
541
569
|
The following examples use truncated temporary directories for illustration purposes only. In
|
@@ -614,6 +642,19 @@ Copies file from current location to new location while answering itself so it c
|
|
614
642
|
Pathname("input.txt").copy Pathname("output.txt") # => Pathname("input.txt")
|
615
643
|
----
|
616
644
|
|
645
|
+
===== #delete
|
646
|
+
|
647
|
+
Deletes file or directory and answers itself so it can be chained.
|
648
|
+
|
649
|
+
[source,ruby]
|
650
|
+
----
|
651
|
+
# When path exists.
|
652
|
+
Pathname("/example.txt").touch.delete # => Pathname("/example")
|
653
|
+
|
654
|
+
# When path doesn't exist.
|
655
|
+
Pathname("/example.txt").delete # => Errno::ENOENT
|
656
|
+
----
|
657
|
+
|
617
658
|
===== #directories
|
618
659
|
|
619
660
|
Answers all directories or filtered directories for current path.
|
data/lib/refinements/arrays.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Refinements
|
4
|
+
# Provides additional enhancements to the Array primitive.
|
4
5
|
module Arrays
|
5
6
|
refine Array do
|
6
|
-
def compress =
|
7
|
+
def compress = dup.compress!
|
7
8
|
|
8
|
-
def compress!
|
9
|
+
def compress!
|
10
|
+
compact!
|
11
|
+
delete_if { |element| element.respond_to?(:empty?) && element.empty? }
|
12
|
+
end
|
9
13
|
|
10
14
|
def excluding(*elements) = self - elements.flatten
|
11
15
|
|
@@ -17,7 +21,7 @@ module Refinements
|
|
17
21
|
|
18
22
|
def maximum(key) = map(&key).max
|
19
23
|
|
20
|
-
def mean = size.zero? ? 0 : sum(0) / size
|
24
|
+
def mean = size.zero? ? 0 : sum(0.0) / size
|
21
25
|
|
22
26
|
def minimum(key) = map(&key).min
|
23
27
|
|
data/lib/refinements/hashes.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Refinements
|
4
|
+
# Provides additional enhancements to the Hash primitive.
|
4
5
|
module Hashes
|
5
6
|
refine Hash.singleton_class do
|
6
7
|
def infinite
|
@@ -11,6 +12,14 @@ module Refinements
|
|
11
12
|
end
|
12
13
|
|
13
14
|
refine Hash do
|
15
|
+
def compress = dup.compress!
|
16
|
+
|
17
|
+
def compress!
|
18
|
+
return self if empty?
|
19
|
+
|
20
|
+
compact!.delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
|
21
|
+
end
|
22
|
+
|
14
23
|
def deep_merge other
|
15
24
|
clazz = self.class
|
16
25
|
|
@@ -62,13 +71,13 @@ module Refinements
|
|
62
71
|
end
|
63
72
|
end
|
64
73
|
|
65
|
-
def stringify_keys =
|
74
|
+
def stringify_keys = transform_keys(&:to_s)
|
66
75
|
|
67
|
-
def stringify_keys! =
|
76
|
+
def stringify_keys! = transform_keys!(&:to_s)
|
68
77
|
|
69
|
-
def symbolize_keys =
|
78
|
+
def symbolize_keys = transform_keys(&:to_sym)
|
70
79
|
|
71
|
-
def symbolize_keys! =
|
80
|
+
def symbolize_keys! = transform_keys!(&:to_sym)
|
72
81
|
|
73
82
|
def use &block
|
74
83
|
return [] unless block
|
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/ios.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require "pathname"
|
4
4
|
|
5
5
|
module Refinements
|
6
|
+
# Provides additional enhancements to the Pathname primitive.
|
6
7
|
module Pathnames
|
7
8
|
refine Kernel do
|
8
|
-
# :reek:UncommunicativeMethodName
|
9
9
|
def Pathname object
|
10
10
|
return super(String(object)) unless object
|
11
11
|
|
@@ -24,7 +24,7 @@ module Refinements
|
|
24
24
|
new(root).files(pattern).each { |path| require path.to_s }
|
25
25
|
end
|
26
26
|
|
27
|
-
def root = new(
|
27
|
+
def root = new(File::SEPARATOR)
|
28
28
|
end
|
29
29
|
|
30
30
|
refine Pathname do
|
@@ -38,6 +38,8 @@ module Refinements
|
|
38
38
|
self
|
39
39
|
end
|
40
40
|
|
41
|
+
def delete = super && self
|
42
|
+
|
41
43
|
def directories pattern = "*", flag: File::FNM_SYSCASE
|
42
44
|
glob(pattern, flag).select(&:directory?).sort
|
43
45
|
end
|
data/lib/refinements/strings.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Refinements
|
4
|
+
# Provides additional enhancements to the String primitive.
|
4
5
|
module Strings
|
5
6
|
DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
|
6
7
|
|
7
8
|
refine String do
|
8
|
-
def blank? = match?(/\A
|
9
|
+
def blank? = empty? || match?(/\A[[:space:]]*\z/)
|
9
10
|
|
10
11
|
def camelcase
|
11
12
|
return up unless match? DELIMITERS
|
@@ -35,7 +36,7 @@ module Refinements
|
|
35
36
|
def indent multiplier = 1, padding: " "
|
36
37
|
return self if multiplier.negative?
|
37
38
|
|
38
|
-
padding * multiplier + self
|
39
|
+
(padding * multiplier) + self
|
39
40
|
end
|
40
41
|
|
41
42
|
def last number = 0
|
data/lib/refinements/structs.rb
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: 8.
|
4
|
+
version: 8.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -28,7 +28,7 @@ cert_chain:
|
|
28
28
|
lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
|
29
29
|
W2A=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2021-
|
31
|
+
date: 2021-10-03 00:00:00.000000000 Z
|
32
32
|
dependencies: []
|
33
33
|
description:
|
34
34
|
email:
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
requirements: []
|
78
|
-
rubygems_version: 3.2.
|
78
|
+
rubygems_version: 3.2.28
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: A collection of refinements to core Ruby objects.
|
metadata.gz.sig
CHANGED
Binary file
|