refinements 8.3.0 → 8.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d389fcb07d681440a24f0b368c81a76948e15b71287a850e857f8e018fc973da
4
- data.tar.gz: 3f7a815dbc49376aad77ab549e77bf9e607bec74ff136b537dfccc371649fe4a
3
+ metadata.gz: 0b633f00ddb573cba22fcf647e293a7f4544fecc82ad3869d9c3528d0bd8e1aa
4
+ data.tar.gz: 00ef7df42687d801237b8b27563aaa028e19b75a4764c32a3c2220f58186dbe0
5
5
  SHA512:
6
- metadata.gz: d7269907e701c6917bb5c096af4bbf1650d03b8ffb752b56c37baa895e8eff649359246b79e0a19b3b790d6dde60711a06aeb0a37b3da0c080a64bbcc54e96bf
7
- data.tar.gz: 5cbd5fd8f553c47fa5f77e4145c48af1ac3467927fb09aae8db48639a92c6000c255b75d66d90824474c7dbffd10ef19ee5581e3d5da83f4bb0526d0d8d1a2e1
6
+ metadata.gz: edb16cbce2ab22b6b95303751e87f09037dd570b38ffb7e6620d91a3e8e7bc9293fdcf4a4378e091847b12ccb80bd5d57c5bab22b0d930507327e54c29c9c855
7
+ data.tar.gz: 5767133f63df1a255b0ac9d6f9ff1ab6c8dfc73d237968a3cea225e3d2be4964fd8aa2298c7047cb81a8594ba6a9f4a676738d485519b696efeee20ddfe4b51d
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -107,13 +107,14 @@ The following sections demonstrate how each refinement enriches your objects wit
107
107
 
108
108
  ===== #compress
109
109
 
110
- Removes `nil` and empty values without mutating itself.
110
+ Removes `nil` and empty objects without mutating itself.
111
111
 
112
112
  [source,ruby]
113
113
  ----
114
- example = ["An", nil, "", "Example"]
115
- example.compress # => ["An", "Example"]
116
- example # => ["An", nil, "", "Example"]
114
+ object = Object.new
115
+ example = [1, "blueberry", nil, "", [], {}, object]
116
+ example.compress # => [1, "blueberry", object]
117
+ example # => [1, "blueberry", nil, "", [], {}, object]
117
118
  ----
118
119
 
119
120
  ===== #compress!
@@ -122,9 +123,10 @@ Removes `nil` and empty values while mutating itself.
122
123
 
123
124
  [source,ruby]
124
125
  ----
125
- example = ["An", nil, "", "Example"]
126
- example.compress! # => ["An", "Example"]
127
- example # => ["An", "Example"]
126
+ object = Object.new
127
+ example = [1, "blueberry", nil, "", [], {}, object]
128
+ example.compress # => [1, "blueberry", object]
129
+ example # => [1, "blueberry", object]
128
130
  ----
129
131
 
130
132
  ===== #excluding
@@ -290,7 +292,7 @@ example[:b] # => []
290
292
 
291
293
  ===== #compress
292
294
 
293
- Removes empty objects without mutating itself.
295
+ Removes `nil` and empty objects without mutating itself.
294
296
 
295
297
  [source,ruby]
296
298
  ----
@@ -302,7 +304,7 @@ example # => {a: 1, b: "blueberry", c: nil, d: "", e: [], f: {}, g: ob
302
304
 
303
305
  ===== #compress!
304
306
 
305
- Removes empty objects while mutating itself.
307
+ Removes `nil` and empty objects while mutating itself.
306
308
 
307
309
  [source,ruby]
308
310
  ----
@@ -640,6 +642,19 @@ Copies file from current location to new location while answering itself so it c
640
642
  Pathname("input.txt").copy Pathname("output.txt") # => Pathname("input.txt")
641
643
  ----
642
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
+
643
658
  ===== #directories
644
659
 
645
660
  Answers all directories or filtered directories for current path.
@@ -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
 
@@ -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
 
@@ -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.4.1"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
10
  end
11
11
  end
@@ -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.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.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-09-26 00:00:00.000000000 Z
31
+ date: 2021-10-03 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
metadata.gz.sig CHANGED
Binary file