refinements 8.3.0 → 8.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,9 +4,12 @@ module Refinements
4
4
  # Provides additional enhancements to the Array primitive.
5
5
  module Arrays
6
6
  refine Array do
7
- def compress = compact.reject(&:empty?)
7
+ def compress = dup.compress!
8
8
 
9
- def compress! = replace(compress)
9
+ def compress!
10
+ compact!
11
+ delete_if { |element| element.respond_to?(:empty?) && element.empty? }
12
+ end
10
13
 
11
14
  def excluding(*elements) = self - elements.flatten
12
15
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ # Provides additional enhancements to Class objects.
5
+ module Classes
6
+ refine Class do
7
+ def descendants
8
+ ObjectSpace.each_object(singleton_class)
9
+ .reject { |klass| klass.singleton_class? || klass == self }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -15,6 +15,8 @@ module Refinements
15
15
  def compress = dup.compress!
16
16
 
17
17
  def compress!
18
+ return self if empty?
19
+
18
20
  compact!.delete_if { |_key, value| value.respond_to?(:empty?) && value.empty? }
19
21
  end
20
22
 
@@ -40,6 +42,10 @@ module Refinements
40
42
 
41
43
  def deep_symbolize_keys! = replace(deep_symbolize_keys)
42
44
 
45
+ def fetch_value key, *default_value, &block
46
+ fetch(key, *default_value, &block) || default_value.first
47
+ end
48
+
43
49
  # :reek:TooManyStatements
44
50
  def flatten_keys prefix: nil, delimiter: "_", cast: :to_sym
45
51
  fail StandardError, "Unknown cast: #{cast}." unless %i[to_sym to_s].include? cast
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "8.3.0"
8
+ VERSION = "8.5.2"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
10
  end
11
11
  end
@@ -24,12 +24,16 @@ 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
31
- def change_dir &block
32
- block ? Dir.chdir(self, &block) : (Dir.chdir self and self)
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,10 +42,16 @@ module Refinements
38
42
  self
39
43
  end
40
44
 
45
+ def deep_touch(...) = make_ancestors.touch(...)
46
+
47
+ def delete = super && self
48
+
41
49
  def directories pattern = "*", flag: File::FNM_SYSCASE
42
50
  glob(pattern, flag).select(&:directory?).sort
43
51
  end
44
52
 
53
+ def empty = file? ? (truncate(0) and self) : remove_tree.make_dir
54
+
45
55
  def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
46
56
 
47
57
  def files(pattern = "*", flag: File::FNM_SYSCASE) = glob(pattern, flag).select(&:file?).sort
@@ -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 number = 0
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
- max = Integer number
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
- return self if multiplier.negative?
38
-
39
- (padding * multiplier) + self
30
+ multiplier.negative? ? self : (padding * multiplier) + self
40
31
  end
41
32
 
42
- def last number = 0
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
- min = Integer number
38
+ self[(minimum + 1)..]
39
+ end
46
40
 
47
- return self[size - 1] if min.zero?
48
- return "" if min.negative?
41
+ def pluralize(suffix, replace: /$/, count: 0) = count.abs == 1 ? self : sub(replace, suffix)
49
42
 
50
- self[(min + 1)..]
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
 
@@ -0,0 +1,12 @@
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
+ def call *arguments, &block
8
+ proc { |receiver| receiver.public_send self, *arguments, &block }
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/refinements.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "refinements/identity"
4
4
  require "refinements/arrays"
5
+ require "refinements/classes"
5
6
  require "refinements/big_decimals"
6
7
  require "refinements/date_times"
7
8
  require "refinements/hashes"
@@ -10,3 +11,4 @@ require "refinements/pathnames"
10
11
  require "refinements/strings"
11
12
  require "refinements/string_ios"
12
13
  require "refinements/structs"
14
+ require "refinements/symbols"
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.3.0
4
+ version: 8.5.2
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-09-26 00:00:00.000000000 Z
31
+ date: 2021-11-20 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -44,6 +44,7 @@ files:
44
44
  - lib/refinements.rb
45
45
  - lib/refinements/arrays.rb
46
46
  - lib/refinements/big_decimals.rb
47
+ - lib/refinements/classes.rb
47
48
  - lib/refinements/date_times.rb
48
49
  - lib/refinements/hashes.rb
49
50
  - lib/refinements/identity.rb
@@ -52,6 +53,7 @@ files:
52
53
  - lib/refinements/string_ios.rb
53
54
  - lib/refinements/strings.rb
54
55
  - lib/refinements/structs.rb
56
+ - lib/refinements/symbols.rb
55
57
  homepage: https://www.alchemists.io/projects/refinements
56
58
  licenses:
57
59
  - Apache-2.0
@@ -59,6 +61,7 @@ metadata:
59
61
  bug_tracker_uri: https://github.com/bkuhlmann/refinements/issues
60
62
  changelog_uri: https://www.alchemists.io/projects/refinements/changes.html
61
63
  documentation_uri: https://www.alchemists.io/projects/refinements
64
+ rubygems_mfa_required: 'true'
62
65
  source_code_uri: https://github.com/bkuhlmann/refinements
63
66
  post_install_message:
64
67
  rdoc_options: []
@@ -75,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
78
  - !ruby/object:Gem::Version
76
79
  version: '0'
77
80
  requirements: []
78
- rubygems_version: 3.2.28
81
+ rubygems_version: 3.2.31
79
82
  signing_key:
80
83
  specification_version: 4
81
84
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- � .�zz{|\�ȧ0��j2EZ���-,�2_*������R�<�a��_.D��G
2
- DC��yr*$��q�O�J�sL(Uڐ�����@������℺����B�ԗXW&&��!��E�*�I���������F�
1
+ �|$I.�\Kb��]�� O��V�_X�9�ŷ���f�