quietly 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/quietly.rb +40 -0
  3. metadata +48 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6cf18b68dae3b1ea412963a346bd0cafa840c594
4
+ data.tar.gz: 264c11a30b3dbacc43f0323a3a2462b66ce76216
5
+ SHA512:
6
+ metadata.gz: dd81170f1b5f1a31ff96be90475dea4688b913d01483b118833c288acacc24f0ccc75359dd1a9108f29b07411fee485c8b099ce2afc19a714701f9ec41471a99
7
+ data.tar.gz: 26229eee6e5e53d26ce0cf22bbb334c3461afc7d05a1d056891afebecdb13d03fb6c3b0707a9ed864132703d0f7d9e35ab602492cb293fb36ddd1ee0e9f073ed
data/lib/quietly.rb ADDED
@@ -0,0 +1,40 @@
1
+ ##
2
+ # Silences all output to STDOUT.
3
+ def quietly(&block); whisper File.new(File::NULL,"w"), false, &block end
4
+
5
+ ##
6
+ # Silences all output to STDOUT and STDERR.
7
+ def silently(&block); whisper File.new(File::NULL,"w"), true, &block end
8
+
9
+ ##
10
+ # Splits output between all given IO instances.
11
+ # @param [*IO] with The IO instances to split between.
12
+ def converse(*with, &block) whisper Quietly::JointIO.new(*with), true, &block end
13
+
14
+ ##
15
+ # Redirects output to the given IO instance.
16
+ # @param [IO] to The IO instance to redirect to.
17
+ # @param [Boolean] redir_errs If true, redirects STDERR as well as STDOUT.
18
+ def whisper(to, redir_errs=false, &block)
19
+ orig_stdout = $stdout.clone
20
+ $stdout = to
21
+
22
+ if redir_errs
23
+ orig_stderr = $stderr.clone
24
+ $stderr = to
25
+ end
26
+
27
+ yield
28
+ ensure
29
+ $stdout = orig_stdout
30
+ $stderr = orig_stderr if redir_errs
31
+ end
32
+
33
+ module Quietly
34
+ ##
35
+ # Utility class used for redirecting to multiple outputs.
36
+ class JointIO < IO
37
+ def initialize(*outs) @outs = outs end
38
+ def write(string) @outs.each {|out| out.write string} end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quietly
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ platform: ruby
6
+ authors:
7
+ - tripl3dogdare
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Quietly aims to make dealing with IO redirection easy. It originally
14
+ started as a simple function to silence output to stdout within a certain block,
15
+ cleaning up and abstracting away the process of dealing with the IO pointers. Eventually,
16
+ it expanded into a simple but effective tool for dealing with any instance where
17
+ you need to redirect, split, or silence output.
18
+ email:
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - lib/quietly.rb
24
+ homepage: http://rubygems.org/gems/quietly
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.6.11
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Makes IO redirection simple and easy.
48
+ test_files: []