refinements 7.10.0 → 7.11.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: 2b7b36399c299675bc98b26334acc2466c5c506849e34b36534f21d2eed72e57
4
- data.tar.gz: 0d00c8e399a0d43c21dafef5985e9d0eb51fe7d544fbe93f4d184eafa75018a8
3
+ metadata.gz: a5a299dfa7a3355d5cb068cc6638ed41ca9ac4980ed69f6aabb0e1608cc96e95
4
+ data.tar.gz: 4b12b5237fc97f5609677b8f010156ef9a1d00d5004fe48d1cfa4d32df15f602
5
5
  SHA512:
6
- metadata.gz: 558191fc552ba160302b9189b8bd2e3ed17ceaee226426cf9453c0c65b8ca0e771b9e85be1e5453c8c1438bc52511a45afc218c72329c17570a6036b65e9f91f
7
- data.tar.gz: 69436b5353f1541b644f9ca72346da713bd8bb1c0f9595983392881727f06ea46ecacdea1412a929981ee24e0243865c6ac9274e747f04d3584c85216e7e300b
6
+ metadata.gz: 248e66b7141e5e29f68c60aae0a3eac49934830053e9e5ce7082b0164e63b42ee9c536d8b46d4f86c7f570a85f1838415939b5955d66bd93f5df2eeefe66a5d7
7
+ data.tar.gz: 399fc17b0857236d4d58668857d690ddb63deba8fd9de10c372f2d3618c93edb31a9574f166c01d6aee884d4d856f067dfc2b68eddedb80d90d70a656595d82d
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -22,6 +22,7 @@ Enhances the following objects:
22
22
  * DateTime
23
23
  * File
24
24
  * Hash
25
+ * IO
25
26
  * Pathname
26
27
  * String
27
28
  * StringIO
@@ -79,7 +80,7 @@ If all refinements are not desired, add the following to your `+Gemfile+` instea
79
80
  gem "refinements", require: false
80
81
  ----
81
82
 
82
- then require the specific refinement, as needed. Example:
83
+ ...then require the specific refinement, as needed. Example:
83
84
 
84
85
  [source,ruby]
85
86
  ----
@@ -88,6 +89,7 @@ require "refinements/big_decimals"
88
89
  require "refinements/date_times"
89
90
  require "refinements/files"
90
91
  require "refinements/hashes"
92
+ require "refinements/ios"
91
93
  require "refinements/pathnames"
92
94
  require "refinements/strings"
93
95
  require "refinements/string_ios"
@@ -106,6 +108,7 @@ class Example
106
108
  using Refinements::DateTimes
107
109
  using Refinements::Files
108
110
  using Refinements::Hashes
111
+ using Refinements::IOs
109
112
  using Refinements::Pathnames
110
113
  using Refinements::Strings
111
114
  using Refinements::StringIOs
@@ -463,6 +466,69 @@ example = {unit: "221B", street: "Baker Street", city: "London", country: "UK"}
463
466
  example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
464
467
  ----
465
468
 
469
+ ==== IO
470
+
471
+ ===== .void
472
+
473
+ Answers an IO stream which points to `/dev/null` in order to ignore any reads or writes to the
474
+ stream. When given a block, the stream will automatically close upon block exit. When not given a
475
+ block, you'll need to close the stream manually.
476
+
477
+ [source,ruby]
478
+ ----
479
+ io = IO.void
480
+ io.closed? # => false
481
+
482
+ io = IO.void { |void| void.write "nevermore" }
483
+ io.closed? # => true
484
+ ----
485
+
486
+ ===== #squelch
487
+
488
+ Temporarily ignores any reads/writes for current stream for all code executed within the block. When
489
+ not given a block, it answers itself.
490
+
491
+ [source,ruby]
492
+ ----
493
+ io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
494
+ io.squelch { io.write "Test" }
495
+ io.reread # => ""
496
+ ----
497
+
498
+ ===== #redirect
499
+
500
+ Redirects current stream to other stream when given a block. Without a block, the original stream is
501
+ answered instead.
502
+
503
+ [source,ruby]
504
+ ----
505
+ io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
506
+ other = IO.new IO.sysopen(Pathname("other.txt").to_s, "w+")
507
+
508
+ io.redirect other # => `io`
509
+
510
+ io.redirect(other) { |stream| stream.write "test" }
511
+ .close # => ""
512
+ other.close # => "test"
513
+ ----
514
+
515
+ ===== #reread
516
+
517
+ Answers full stream by rewinding to beginning of stream and reading all content.
518
+
519
+ [source,ruby]
520
+ ----
521
+ io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
522
+ io.write "This is a test."
523
+
524
+ io.reread # => "This is a test."
525
+ io.reread 4 # => "This"
526
+
527
+ buffer = "".dup
528
+ io.reread(buffer: buffer)
529
+ buffer # => "This is a test."
530
+ ----
531
+
466
532
  ==== Pathname
467
533
 
468
534
  ===== Pathname
@@ -6,6 +6,7 @@ require "refinements/big_decimals"
6
6
  require "refinements/date_times"
7
7
  require "refinements/files"
8
8
  require "refinements/hashes"
9
+ require "refinements/ios"
9
10
  require "refinements/pathnames"
10
11
  require "refinements/strings"
11
12
  require "refinements/string_ios"
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.10.0"
8
+ VERSION = "7.11.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ module IOs
5
+ refine IO.singleton_class do
6
+ def void
7
+ new(sysopen("/dev/null", "w+")).then do |io|
8
+ return io unless block_given?
9
+
10
+ yield io
11
+ io.tap(&:close)
12
+ end
13
+ end
14
+ end
15
+
16
+ refine IO do
17
+ def squelch &block
18
+ self.class.void.then { |void| redirect(void, &block) }
19
+ end
20
+
21
+ def redirect other
22
+ return self unless block_given?
23
+
24
+ backup = dup
25
+ reopen other
26
+ yield self
27
+ reopen backup
28
+ end
29
+
30
+ def reread length = nil, buffer: nil
31
+ tap(&:rewind).read length, buffer
32
+ end
33
+ end
34
+ end
35
+ end
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: 7.10.0
4
+ version: 7.11.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: 2020-09-27 00:00:00.000000000 Z
31
+ date: 2020-10-06 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
@@ -244,6 +244,7 @@ files:
244
244
  - lib/refinements/files.rb
245
245
  - lib/refinements/hashes.rb
246
246
  - lib/refinements/identity.rb
247
+ - lib/refinements/ios.rb
247
248
  - lib/refinements/pathnames.rb
248
249
  - lib/refinements/string_ios.rb
249
250
  - lib/refinements/strings.rb
metadata.gz.sig CHANGED
Binary file