refinements 9.5.0 → 9.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06c161de8cf1a100c8df6267ef2116368743557dac4504e9617b19dd063520aa
4
- data.tar.gz: 60389a48bc41a581d835ac67c80e71a8db438ddbccf070336e1128d4d430e87a
3
+ metadata.gz: 5c0144180dd3a5cabe861b385cd0c766eaf54280ca6812dc6e82db4e564ce6c0
4
+ data.tar.gz: b339710c168c98fffbe5b1994031f033041c9f6c16b0df96555cb80fd5cd7269
5
5
  SHA512:
6
- metadata.gz: 95c680f9fe5df9820d72462e40984eafe398b0cf81589b6525026978a477950723608d8d39b89b3fe0c61e888ce3a2a166d2e54ec26676a3c9621f6b712e3828
7
- data.tar.gz: b3743029174a74733328346ce1264d9f7dab9876222deb4a3b3f96a38817cf8b7c0b35eabc62639b5f7e7f4f2e1572282d1f31952e6c55b90d6f65df2b190bef
6
+ metadata.gz: 926090205f29ac111494e00e7de37b59b8549c6f979c8a0d62d852e9d87193093073ac0f005564243fc472eacf4de68f62bea8b1d45f3f363e113805758f726d
7
+ data.tar.gz: 22a524d073a48922d6347119f01f4c059bbd2bba8f65a2e6573951b137b772dc3f7797a3596ccb850bb63159a9b2ab501bb334f7ac8a80f66ca93f55886bdb09
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -21,6 +21,8 @@ Enhances the following objects:
21
21
  * DateTime
22
22
  * Hash
23
23
  * IO
24
+ * LogDevice
25
+ * Logger
24
26
  * Pathname
25
27
  * String
26
28
  * StringIO
@@ -73,6 +75,8 @@ require "refinements/strings"
73
75
  require "refinements/string_ios"
74
76
  require "refinements/structs"
75
77
  require "refinements/symbols"
78
+ require "refinements/log_devices"
79
+ require "refinements/loggers"
76
80
  ----
77
81
 
78
82
  === Using
@@ -93,6 +97,8 @@ class Example
93
97
  using Refinements::StringIOs
94
98
  using Refinements::Structs
95
99
  using Refinements::Symbols
100
+ using Refinements::LogDevices
101
+ using Refinements::Loggers
96
102
  end
97
103
  ----
98
104
 
@@ -102,6 +108,24 @@ The following sections demonstrate how each refinement enriches your objects wit
102
108
 
103
109
  ==== Array
104
110
 
111
+ ===== #combinatorial?
112
+
113
+ Answers if an array is equal to another array when the elements are equal but in any order and/or subset.
114
+
115
+ [source,ruby]
116
+ ----
117
+ example = %w[a b c]
118
+
119
+ example.combinatorial? %w[a b c] # true
120
+ example.combinatorial? %w[c a b] # true
121
+ example.combinatorial? %w[c] # true
122
+ example.combinatorial? %w[c b] # true
123
+ example.combinatorial? %w[x] # false
124
+ example.combinatorial? %w[z b c] # false
125
+ example.combinatorial? %w[a b c d] # false
126
+ example.combinatorial? [] # false
127
+ ----
128
+
105
129
  ===== #compress
106
130
 
107
131
  Removes `nil` and empty objects without mutating itself.
@@ -596,6 +620,54 @@ io.squelch { io.write "Test" } # "#<IO:fd 20>"
596
620
  io.reread # ""
597
621
  ----
598
622
 
623
+ ==== LogDevice
624
+
625
+ ===== #reread
626
+
627
+ Answers previously written content by rewinding to beginning of device.
628
+
629
+ [source,ruby]
630
+ ----
631
+ # With File.
632
+ device = Logger::LogDevice.new "test.log"
633
+ device.write "Test."
634
+ device.reread # "Test."
635
+
636
+ # With StringIO.
637
+ device = Logger::LogDevice.new StringIO.new
638
+ device.write "Test."
639
+ device.reread # "Test."
640
+
641
+ # With STDOUT.
642
+ device = Logger::LogDevice.new $stdout
643
+ device.write "Test."
644
+ device.reread # ""
645
+ ----
646
+
647
+ ==== Logger
648
+
649
+ ===== #reread
650
+
651
+ Answers previously written content by rewinding to beginning of log.
652
+
653
+ [source,ruby]
654
+ ----
655
+ # With File.
656
+ logger = Logger.new "test.log"
657
+ logger.write "Test."
658
+ logger.reread # "Test."
659
+
660
+ # With StringIO.
661
+ logger = Logger.new StringIO.new
662
+ logger.write "Test."
663
+ logger.reread # "Test."
664
+
665
+ # With STDOUT.
666
+ logger = Logger.new $stdout
667
+ logger.write "Test."
668
+ logger.reread # ""
669
+ ----
670
+
599
671
  ==== Pathname
600
672
 
601
673
  ===== Pathname
@@ -8,6 +8,8 @@ module Refinements
8
8
  refine Array do
9
9
  import_methods Shared::Enumerables::Many
10
10
 
11
+ def combinatorial?(other) = !other.empty? && size == union(other).size
12
+
11
13
  def compress = dup.compress!
12
14
 
13
15
  def compress!
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/shared/ios/reread"
4
+
3
5
  module Refinements
4
6
  # Provides additional enhancements to the IO primitive.
5
7
  module IOs
@@ -15,6 +17,8 @@ module Refinements
15
17
  end
16
18
 
17
19
  refine IO do
20
+ import_methods Shared::IOs::Reread
21
+
18
22
  def redirect other
19
23
  return self unless block_given?
20
24
 
@@ -24,8 +28,6 @@ module Refinements
24
28
  reopen backup
25
29
  end
26
30
 
27
- def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
28
-
29
31
  def squelch(&) = self.class.void.then { |void| redirect(void, &) }
30
32
  end
31
33
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "logger"
4
+ require "refinements/string_ios"
5
+
6
+ module Refinements
7
+ # Provides additional enhancements to a log device.
8
+ module LogDevices
9
+ using StringIOs
10
+
11
+ refine Logger::LogDevice do
12
+ def reread
13
+ case dev
14
+ when File then dev.class.new(dev).read
15
+ when StringIO then dev.reread
16
+ else ""
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/log_devices"
4
+
5
+ module Refinements
6
+ # Provides additional enhancements to a logger.
7
+ module Loggers
8
+ using LogDevices
9
+
10
+ refine Logger do
11
+ def reread = @logdev.reread
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ module Shared
5
+ module IOs
6
+ # Provides shared functionality for I/O object rewinding.
7
+ module Reread
8
+ def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "stringio"
4
+ require "refinements/shared/ios/reread"
4
5
 
5
6
  module Refinements
6
7
  # Provides additional enhancements to the StringIO primitive.
7
8
  module StringIOs
8
9
  refine StringIO do
9
- def reread(length = nil, buffer: nil) = tap(&:rewind).read(length, buffer)
10
+ import_methods Shared::IOs::Reread
10
11
  end
11
12
  end
12
13
  end
data/lib/refinements.rb CHANGED
@@ -10,3 +10,5 @@ require "refinements/strings"
10
10
  require "refinements/string_ios"
11
11
  require "refinements/structs"
12
12
  require "refinements/symbols"
13
+ require "refinements/log_devices"
14
+ require "refinements/loggers"
data/refinements.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "refinements"
5
- spec.version = "9.5.0"
5
+ spec.version = "9.6.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://www.alchemists.io/projects/refinements"
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: 9.5.0
4
+ version: 9.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  CxDe2+VuChj4I1nvIHdu+E6XoEVlanUPKmSg6nddhkKn2gC45Kyzh6FZqnzH/CRp
29
29
  RFE=
30
30
  -----END CERTIFICATE-----
31
- date: 2022-06-25 00:00:00.000000000 Z
31
+ date: 2022-07-17 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -47,8 +47,11 @@ files:
47
47
  - lib/refinements/date_times.rb
48
48
  - lib/refinements/hashes.rb
49
49
  - lib/refinements/ios.rb
50
+ - lib/refinements/log_devices.rb
51
+ - lib/refinements/loggers.rb
50
52
  - lib/refinements/pathnames.rb
51
53
  - lib/refinements/shared/enumerables/many.rb
54
+ - lib/refinements/shared/ios/reread.rb
52
55
  - lib/refinements/string_ios.rb
53
56
  - lib/refinements/strings.rb
54
57
  - lib/refinements/structs.rb
@@ -80,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
83
  - !ruby/object:Gem::Version
81
84
  version: '0'
82
85
  requirements: []
83
- rubygems_version: 3.3.16
86
+ rubygems_version: 3.3.18
84
87
  signing_key:
85
88
  specification_version: 4
86
89
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
Binary file