fedux_org-stdlib 0.11.4 → 0.11.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/fedux_org_stdlib/core_ext/kernel/reporting.rb +116 -0
- data/lib/fedux_org_stdlib/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc427727280e467a41cb572e2f9bcb7a6cc6bacd
|
4
|
+
data.tar.gz: 8f4fe1b5a4dfec824b8d3522bc8ee3e741a8a034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5979eb7ca3a7adfb24bc104127ddad9337ee9d47374d10744b4b17feb7b9d3fd4d2dc1abba807d30587d54c40370442960df7e0ec50adb1c656f17ad3edc219
|
7
|
+
data.tar.gz: 30004823eb995f781e8c547f2a4d62cc7d0e656b6c6ab897b99be338b1a87ef589c30814f029ddffcdd89befd35cec95c1005d565bbb829b68ee6ac6abde41a9
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
module Kernel
|
5
|
+
# Sets $VERBOSE to nil for the duration of the block and back to its original
|
6
|
+
# value afterwards.
|
7
|
+
#
|
8
|
+
# silence_warnings do
|
9
|
+
# value = noisy_call # no warning voiced
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# noisy_call # warning voiced
|
13
|
+
def silence_warnings
|
14
|
+
with_warnings(nil) { yield }
|
15
|
+
end
|
16
|
+
|
17
|
+
# Sets $VERBOSE to +true+ for the duration of the block and back to its
|
18
|
+
# original value afterwards.
|
19
|
+
def enable_warnings
|
20
|
+
with_warnings(true) { yield }
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sets $VERBOSE for the duration of the block and back to its original
|
24
|
+
# value afterwards.
|
25
|
+
def with_warnings(flag)
|
26
|
+
old_verbose, $VERBOSE = $VERBOSE, flag
|
27
|
+
yield
|
28
|
+
ensure
|
29
|
+
$VERBOSE = old_verbose
|
30
|
+
end
|
31
|
+
|
32
|
+
# For compatibility
|
33
|
+
def silence_stderr #:nodoc:
|
34
|
+
silence_stream(STDERR) { yield }
|
35
|
+
end
|
36
|
+
|
37
|
+
# Deprecated : this method is not thread safe
|
38
|
+
# Silences any stream for the duration of the block.
|
39
|
+
#
|
40
|
+
# silence_stream(STDOUT) do
|
41
|
+
# puts 'This will never be seen'
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# puts 'But this will'
|
45
|
+
#
|
46
|
+
# This method is not thread-safe.
|
47
|
+
def silence_stream(stream)
|
48
|
+
old_stream = stream.dup
|
49
|
+
stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
|
50
|
+
stream.sync = true
|
51
|
+
yield
|
52
|
+
ensure
|
53
|
+
stream.reopen(old_stream)
|
54
|
+
old_stream.close
|
55
|
+
end
|
56
|
+
|
57
|
+
# Blocks and ignores any exception passed as argument if raised within the block.
|
58
|
+
#
|
59
|
+
# suppress(ZeroDivisionError) do
|
60
|
+
# 1/0
|
61
|
+
# puts 'This code is NOT reached'
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# puts 'This code gets executed and nothing related to ZeroDivisionError was seen'
|
65
|
+
def suppress(*exception_classes)
|
66
|
+
yield
|
67
|
+
rescue *exception_classes
|
68
|
+
end
|
69
|
+
|
70
|
+
# Captures the given stream and returns it:
|
71
|
+
#
|
72
|
+
# stream = capture(:stdout) { puts 'notice' }
|
73
|
+
# stream # => "notice\n"
|
74
|
+
#
|
75
|
+
# stream = capture(:stderr) { warn 'error' }
|
76
|
+
# stream # => "error\n"
|
77
|
+
#
|
78
|
+
# even for subprocesses:
|
79
|
+
#
|
80
|
+
# stream = capture(:stdout) { system('echo notice') }
|
81
|
+
# stream # => "notice\n"
|
82
|
+
#
|
83
|
+
# stream = capture(:stderr) { system('echo error 1>&2') }
|
84
|
+
# stream # => "error\n"
|
85
|
+
def capture(stream)
|
86
|
+
stream = stream.to_s
|
87
|
+
captured_stream = Tempfile.new(stream)
|
88
|
+
stream_io = eval("$#{stream}")
|
89
|
+
origin_stream = stream_io.dup
|
90
|
+
stream_io.reopen(captured_stream)
|
91
|
+
|
92
|
+
yield
|
93
|
+
|
94
|
+
stream_io.rewind
|
95
|
+
return captured_stream.read
|
96
|
+
ensure
|
97
|
+
captured_stream.close
|
98
|
+
captured_stream.unlink
|
99
|
+
stream_io.reopen(origin_stream)
|
100
|
+
end
|
101
|
+
alias :silence :capture
|
102
|
+
|
103
|
+
# Silences both STDOUT and STDERR, even for subprocesses.
|
104
|
+
#
|
105
|
+
# quietly { system 'bundle install' }
|
106
|
+
#
|
107
|
+
# This method is not thread-safe.
|
108
|
+
def quietly
|
109
|
+
silence_stream(STDOUT) do
|
110
|
+
silence_stream(STDERR) do
|
111
|
+
yield
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fedux_org-stdlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max Meyer
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/fedux_org_stdlib/core_ext/hash.rb
|
70
70
|
- lib/fedux_org_stdlib/core_ext/hash/list.rb
|
71
71
|
- lib/fedux_org_stdlib/core_ext/hash/options.rb
|
72
|
+
- lib/fedux_org_stdlib/core_ext/kernel/reporting.rb
|
72
73
|
- lib/fedux_org_stdlib/core_ext/shellwords.rb
|
73
74
|
- lib/fedux_org_stdlib/core_ext/shellwords/clean.rb
|
74
75
|
- lib/fedux_org_stdlib/core_ext/string.rb
|