refinements 8.4.1 → 9.0.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/LICENSE.adoc +207 -155
- data/README.adoc +342 -216
- data/lib/refinements/arrays.rb +1 -1
- data/lib/refinements/hashes.rb +8 -2
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/ios.rb +1 -1
- data/lib/refinements/pathnames.rb +10 -2
- data/lib/refinements/strings.rb +14 -26
- data/lib/refinements/structs.rb +3 -3
- data/lib/refinements/symbols.rb +14 -0
- data/lib/refinements.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +7 -5
- metadata.gz.sig +0 -0
data/lib/refinements/arrays.rb
CHANGED
data/lib/refinements/hashes.rb
CHANGED
@@ -42,6 +42,12 @@ module Refinements
|
|
42
42
|
|
43
43
|
def deep_symbolize_keys! = replace(deep_symbolize_keys)
|
44
44
|
|
45
|
+
# rubocop:disable Style/MethodDefParentheses
|
46
|
+
def fetch_value(key, *default_value, &)
|
47
|
+
fetch(key, *default_value, &) || default_value.first
|
48
|
+
end
|
49
|
+
# rubocop:enable Style/MethodDefParentheses
|
50
|
+
|
45
51
|
# :reek:TooManyStatements
|
46
52
|
def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
|
47
53
|
fail StandardError, "Unknown cast: #{cast}." unless %i[to_sym to_s].include? cast
|
@@ -52,13 +58,13 @@ module Refinements
|
|
52
58
|
next flat.merge flat_key.public_send(cast) => value unless value.is_a? self.class
|
53
59
|
|
54
60
|
flat.merge(
|
55
|
-
recurse { value.flatten_keys prefix: flat_key, delimiter
|
61
|
+
recurse { value.flatten_keys prefix: flat_key, delimiter:, cast: }
|
56
62
|
)
|
57
63
|
end
|
58
64
|
end
|
59
65
|
|
60
66
|
def flatten_keys! prefix: nil, delimiter: "_", cast: :to_sym
|
61
|
-
replace flatten_keys(prefix
|
67
|
+
replace flatten_keys(prefix:, delimiter:, cast:)
|
62
68
|
end
|
63
69
|
|
64
70
|
def recurse &block
|
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/ios.rb
CHANGED
@@ -26,7 +26,7 @@ module Refinements
|
|
26
26
|
|
27
27
|
def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
|
28
28
|
|
29
|
-
def squelch(&
|
29
|
+
def squelch(&) = self.class.void.then { |void| redirect(void, &) }
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -28,8 +28,12 @@ module Refinements
|
|
28
28
|
end
|
29
29
|
|
30
30
|
refine Pathname do
|
31
|
-
def change_dir
|
32
|
-
|
31
|
+
def change_dir
|
32
|
+
if block_given?
|
33
|
+
Dir.chdir(self) { |path| yield Pathname(path) }
|
34
|
+
else
|
35
|
+
Dir.chdir self and self
|
36
|
+
end
|
33
37
|
end
|
34
38
|
|
35
39
|
def copy to
|
@@ -38,12 +42,16 @@ module Refinements
|
|
38
42
|
self
|
39
43
|
end
|
40
44
|
|
45
|
+
def deep_touch(...) = make_ancestors.touch(...)
|
46
|
+
|
41
47
|
def delete = super && self
|
42
48
|
|
43
49
|
def directories pattern = "*", flag: File::FNM_SYSCASE
|
44
50
|
glob(pattern, flag).select(&:directory?).sort
|
45
51
|
end
|
46
52
|
|
53
|
+
def empty = file? ? (truncate(0) and self) : remove_tree.make_dir
|
54
|
+
|
47
55
|
def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
|
48
56
|
|
49
57
|
def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?).sort
|
data/lib/refinements/strings.rb
CHANGED
@@ -16,39 +16,31 @@ module Refinements
|
|
16
16
|
.then { |parts| combine parts, :up }
|
17
17
|
end
|
18
18
|
|
19
|
-
def down
|
20
|
-
return self if empty?
|
21
|
-
|
22
|
-
first.downcase + self[1, size]
|
23
|
-
end
|
19
|
+
def down = empty? ? self : first.downcase + self[1, size]
|
24
20
|
|
25
|
-
def first
|
21
|
+
def first maximum = 0
|
26
22
|
return self if empty?
|
23
|
+
return self[0] if maximum.zero?
|
24
|
+
return "" if maximum.negative?
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
return self[0] if max.zero?
|
31
|
-
return "" if max.negative?
|
32
|
-
|
33
|
-
self[..(max - 1)]
|
26
|
+
self[..(maximum - 1)]
|
34
27
|
end
|
35
28
|
|
36
29
|
def indent multiplier = 1, padding: " "
|
37
|
-
|
38
|
-
|
39
|
-
(padding * multiplier) + self
|
30
|
+
multiplier.negative? ? self : (padding * multiplier) + self
|
40
31
|
end
|
41
32
|
|
42
|
-
def last
|
33
|
+
def last minimum = 0
|
43
34
|
return self if empty?
|
35
|
+
return self[size - 1] if minimum.zero?
|
36
|
+
return "" if minimum.negative?
|
44
37
|
|
45
|
-
|
38
|
+
self[(minimum + 1)..]
|
39
|
+
end
|
46
40
|
|
47
|
-
|
48
|
-
return "" if min.negative?
|
41
|
+
def pluralize(suffix, replace: /$/, count: 0) = count.abs == 1 ? self : sub(replace, suffix)
|
49
42
|
|
50
|
-
|
51
|
-
end
|
43
|
+
def singularize(suffix, replace: "", count: 1) = count.abs == 1 ? sub(suffix, replace) : self
|
52
44
|
|
53
45
|
def snakecase
|
54
46
|
return downcase unless match? DELIMITERS
|
@@ -68,11 +60,7 @@ module Refinements
|
|
68
60
|
|
69
61
|
def to_bool = %w[true yes on t y 1].include?(downcase.strip)
|
70
62
|
|
71
|
-
def up
|
72
|
-
return self if empty?
|
73
|
-
|
74
|
-
first.upcase + self[1, size]
|
75
|
-
end
|
63
|
+
def up = empty? ? self : first.upcase + self[1, size]
|
76
64
|
|
77
65
|
private
|
78
66
|
|
data/lib/refinements/structs.rb
CHANGED
@@ -12,10 +12,10 @@ module Refinements
|
|
12
12
|
end
|
13
13
|
|
14
14
|
refine Struct do
|
15
|
-
def merge(
|
15
|
+
def merge(object = nil) = dup.merge!(object)
|
16
16
|
|
17
|
-
def merge!
|
18
|
-
to_h.merge(**
|
17
|
+
def merge! object = nil
|
18
|
+
to_h.merge(**object.to_h).each { |key, value| self[key] = value }
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Refinements
|
4
|
+
# Provides additional enhancements to the Symbol primitive.
|
5
|
+
module Symbols
|
6
|
+
refine Symbol do
|
7
|
+
# rubocop:disable Style/MethodDefParentheses
|
8
|
+
def call(*arguments, &)
|
9
|
+
proc { |receiver| receiver.public_send self, *arguments, & }
|
10
|
+
end
|
11
|
+
# rubocop:enable Style/MethodDefParentheses
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/refinements.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:
|
4
|
+
version: 9.0.0
|
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-12-26 00:00:00.000000000 Z
|
32
32
|
dependencies: []
|
33
33
|
description:
|
34
34
|
email:
|
@@ -52,13 +52,15 @@ files:
|
|
52
52
|
- lib/refinements/string_ios.rb
|
53
53
|
- lib/refinements/strings.rb
|
54
54
|
- lib/refinements/structs.rb
|
55
|
+
- lib/refinements/symbols.rb
|
55
56
|
homepage: https://www.alchemists.io/projects/refinements
|
56
57
|
licenses:
|
57
|
-
-
|
58
|
+
- Hippocratic-3.0
|
58
59
|
metadata:
|
59
60
|
bug_tracker_uri: https://github.com/bkuhlmann/refinements/issues
|
60
61
|
changelog_uri: https://www.alchemists.io/projects/refinements/changes.html
|
61
62
|
documentation_uri: https://www.alchemists.io/projects/refinements
|
63
|
+
rubygems_mfa_required: 'true'
|
62
64
|
source_code_uri: https://github.com/bkuhlmann/refinements
|
63
65
|
post_install_message:
|
64
66
|
rdoc_options: []
|
@@ -68,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
70
|
requirements:
|
69
71
|
- - "~>"
|
70
72
|
- !ruby/object:Gem::Version
|
71
|
-
version: '3.
|
73
|
+
version: '3.1'
|
72
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
75
|
requirements:
|
74
76
|
- - ">="
|
75
77
|
- !ruby/object:Gem::Version
|
76
78
|
version: '0'
|
77
79
|
requirements: []
|
78
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.3.3
|
79
81
|
signing_key:
|
80
82
|
specification_version: 4
|
81
83
|
summary: A collection of refinements to core Ruby objects.
|
metadata.gz.sig
CHANGED
Binary file
|