refinements 8.0.1 → 8.1.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 +3 -2
- data.tar.gz.sig +0 -0
- data/lib/refinements/arrays.rb +8 -24
- data/lib/refinements/big_decimals.rb +1 -3
- data/lib/refinements/date_times.rb +1 -3
- data/lib/refinements/hashes.rb +10 -30
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/ios.rb +2 -6
- data/lib/refinements/pathnames.rb +11 -36
- data/lib/refinements/string_ios.rb +1 -3
- data/lib/refinements/strings.rb +2 -6
- data/lib/refinements/structs.rb +4 -12
- 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: 6446344f206e8c2b4175dedc5ccd4d14c4bcaadd6d7969fcf04ef3d185143b03
|
4
|
+
data.tar.gz: ccdd0a5a93d36e1c4f4e5ed23b2f29ee3ee1cd3d8654a919ade1ed17841228cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b27775e5e325f98b308bdfd913129074266f75c4601caec7d48e9ca64e7608d24a2ebcbea4795a7548d61db36fecfe8ddbab3593c9aa9df8ca153b63ad41dac
|
7
|
+
data.tar.gz: afe11cd5ac6e81723f4afef741699a7615e96103c85fef24f51749e35ac02c79ffb0c9eb0fc459d63b7bba26f0b3469d251ae562b211fae4b8b29dbac71f02dc
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
p������"����BcND�X�R;A��VPȑsbaǣيL�z�?O�T"
|
2
|
+
8e���A�i��FeY�`b�S]���p�7��������^���H
|
3
|
+
���.g�a=MA=蟌���fl��|$����'�:t3�A�bM3#%���\��<�&-%;��܍Y�iy ���b��Pt+��3%FVb8��yR����&�Y������]j�/)�������"x�Xy��U�
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/refinements/arrays.rb
CHANGED
@@ -3,37 +3,21 @@
|
|
3
3
|
module Refinements
|
4
4
|
module Arrays
|
5
5
|
refine Array do
|
6
|
-
def compress
|
7
|
-
compact.reject(&:empty?)
|
8
|
-
end
|
6
|
+
def compress = compact.reject(&:empty?)
|
9
7
|
|
10
|
-
def compress!
|
11
|
-
replace compress
|
12
|
-
end
|
8
|
+
def compress! = replace(compress)
|
13
9
|
|
14
|
-
def excluding
|
15
|
-
self - elements.flatten
|
16
|
-
end
|
10
|
+
def excluding(*elements) = self - elements.flatten
|
17
11
|
|
18
|
-
def including
|
19
|
-
self + elements.flatten
|
20
|
-
end
|
12
|
+
def including(*elements) = self + elements.flatten
|
21
13
|
|
22
|
-
def intersperse
|
23
|
-
product([elements]).tap(&:pop).flatten.push last
|
24
|
-
end
|
14
|
+
def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)
|
25
15
|
|
26
|
-
def mean
|
27
|
-
size.zero? ? 0 : sum(0) / size
|
28
|
-
end
|
16
|
+
def mean = size.zero? ? 0 : sum(0) / size
|
29
17
|
|
30
|
-
def pad
|
31
|
-
dup.fill value, size..(max - 1)
|
32
|
-
end
|
18
|
+
def pad(value, max: size) = dup.fill(value, size..(max - 1))
|
33
19
|
|
34
|
-
def ring &block
|
35
|
-
[last, *self, first].each_cons 3, &block
|
36
|
-
end
|
20
|
+
def ring(&block) = [last, *self, first].each_cons(3, &block)
|
37
21
|
end
|
38
22
|
end
|
39
23
|
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,25 +23,15 @@ module Refinements
|
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
def deep_merge! other
|
29
|
-
replace deep_merge(other)
|
30
|
-
end
|
26
|
+
def deep_merge!(other) = replace(deep_merge(other))
|
31
27
|
|
32
|
-
def deep_stringify_keys
|
33
|
-
recurse(&:stringify_keys)
|
34
|
-
end
|
28
|
+
def deep_stringify_keys = recurse(&:stringify_keys)
|
35
29
|
|
36
|
-
def deep_stringify_keys!
|
37
|
-
replace deep_stringify_keys
|
38
|
-
end
|
30
|
+
def deep_stringify_keys! = replace(deep_stringify_keys)
|
39
31
|
|
40
|
-
def deep_symbolize_keys
|
41
|
-
recurse(&:symbolize_keys)
|
42
|
-
end
|
32
|
+
def deep_symbolize_keys = recurse(&:symbolize_keys)
|
43
33
|
|
44
|
-
def deep_symbolize_keys!
|
45
|
-
replace deep_symbolize_keys
|
46
|
-
end
|
34
|
+
def deep_symbolize_keys! = replace(deep_symbolize_keys)
|
47
35
|
|
48
36
|
# :reek:TooManyStatements
|
49
37
|
def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
|
@@ -74,21 +62,13 @@ module Refinements
|
|
74
62
|
end
|
75
63
|
end
|
76
64
|
|
77
|
-
def stringify_keys
|
78
|
-
reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
79
|
-
end
|
65
|
+
def stringify_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_s => value }
|
80
66
|
|
81
|
-
def stringify_keys!
|
82
|
-
replace stringify_keys
|
83
|
-
end
|
67
|
+
def stringify_keys! = replace(stringify_keys)
|
84
68
|
|
85
|
-
def symbolize_keys
|
86
|
-
reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
87
|
-
end
|
69
|
+
def symbolize_keys = reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
88
70
|
|
89
|
-
def symbolize_keys!
|
90
|
-
replace symbolize_keys
|
91
|
-
end
|
71
|
+
def symbolize_keys! = replace(symbolize_keys)
|
92
72
|
|
93
73
|
def use &block
|
94
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,58 +42,36 @@ 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 name
|
75
|
-
basename extname
|
76
|
-
end
|
77
|
-
|
78
|
-
def relative_parent root_dir
|
79
|
-
relative_path_from(root_dir).parent
|
80
|
-
end
|
63
|
+
def name = basename(extname)
|
81
64
|
|
82
|
-
def
|
83
|
-
warn "[DEPRECATION]: Pathname#relative_parent_from is deprecated, " \
|
84
|
-
"use Pathname#relative_parent instead."
|
85
|
-
relative_parent root_dir
|
86
|
-
end
|
65
|
+
def relative_parent(root_dir) = relative_path_from(root_dir).parent
|
87
66
|
|
88
|
-
def remove_dir
|
89
|
-
exist? ? (rmdir and self) : self
|
90
|
-
end
|
67
|
+
def remove_dir = exist? ? (rmdir and self) : self
|
91
68
|
|
92
69
|
def remove_tree
|
93
70
|
rmtree if exist?
|
94
71
|
self
|
95
72
|
end
|
96
73
|
|
97
|
-
def rewrite
|
98
|
-
read.then { |content| write yield(content) if block_given? }
|
99
|
-
end
|
74
|
+
def rewrite = read.then { |content| write yield(content) if block_given? }
|
100
75
|
|
101
76
|
def touch at = Time.now
|
102
77
|
exist? ? utime(at, at) : write("")
|
data/lib/refinements/strings.rb
CHANGED
@@ -5,9 +5,7 @@ module Refinements
|
|
5
5
|
DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
|
6
6
|
|
7
7
|
refine String do
|
8
|
-
def blank?
|
9
|
-
match?(/\A\s*\z/)
|
10
|
-
end
|
8
|
+
def blank? = match?(/\A\s*\z/)
|
11
9
|
|
12
10
|
def camelcase
|
13
11
|
return up unless match? DELIMITERS
|
@@ -67,9 +65,7 @@ module Refinements
|
|
67
65
|
.then { |parts| combine parts, :up, "/" }
|
68
66
|
end
|
69
67
|
|
70
|
-
def to_bool
|
71
|
-
%w[true yes on t y 1].include? downcase.strip
|
72
|
-
end
|
68
|
+
def to_bool = %w[true yes on t y 1].include?(downcase.strip)
|
73
69
|
|
74
70
|
def up
|
75
71
|
return self if empty?
|
data/lib/refinements/structs.rb
CHANGED
@@ -3,23 +3,15 @@
|
|
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(**Hash[members.zip values]) : 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
17
|
to_h.merge(**attributes).each { |key, value| self[key] = value }
|
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.0
|
4
|
+
version: 8.1.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:
|
31
|
+
date: 2021-01-16 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.5
|
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
|