silent_stream 1.0.5 → 1.0.6

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: a8973e45d20ed7c5dcbf2c5b2efc32b182cf7450b5ab380e615e25c7f5469cb3
4
- data.tar.gz: 8e4031ed9fab5ca71011f42427e406abaeac5cb8926983394d2f41fb90da0ac5
3
+ metadata.gz: e0674612ee30874ba629342778f29d7b96d6366b0398f2848a4a6958c59c2620
4
+ data.tar.gz: eac29a150200bfeafd87b8b31557f7c93d9d58d2116426ad5b9de55116a37ff0
5
5
  SHA512:
6
- metadata.gz: 62d41a194185eb19b3b121c6d0a8b1ed85447d04babe386514c324b23959bea596f274fa97770579367ac76aa064c1477d210769ec6c8423c51c49bb7dce3c23
7
- data.tar.gz: fd379c47ab834014b71609296e192364e79a0f74b8fbc6eade77bdd629fe5336012bbc68864f2a1027fc4c78ee8daf87c2f5b7d8573c0d1f7e3c557636dfe948
6
+ metadata.gz: 2b5398a3e02ebae7efb82c6582d08762e40dba67bd8d6b5420d2a4f4bdb79d09ee525c22b1c50a8f41b0b44a791c916f9255838b0316a4780349cd96eddc9950
7
+ data.tar.gz: 31604b518d7d6bd7097d557e187302b9d5846f1564e5a77f1774164d14cefd0549540c2a7e83298f7079c7f6a7518917ec96579efd59d3eab5dd408ac0624093
data/.gitignore CHANGED
@@ -17,3 +17,5 @@
17
17
 
18
18
  *.gem
19
19
  /Gemfile.lock
20
+
21
+ /gemfiles/*.lock
@@ -1 +1 @@
1
- ruby-2.5.1
1
+ 2.7.0
@@ -1,7 +1,10 @@
1
1
  ---
2
+ sudo: false
3
+ language: ruby
4
+ cache:
5
+ bundler: true
2
6
  env:
3
7
  global:
4
- - JRUBY_OPTS="-Xcli.debug=true --debug"
5
8
  - CC_TEST_REPORTER_ID=954687c8cc4840dccb8887a7bf1f1f6ea463f6c20c02f20186945ab17995e0ba
6
9
 
7
10
  before_script:
@@ -20,13 +23,17 @@ before_install:
20
23
  - gem install bundler -v 1.16.5
21
24
 
22
25
  install:
23
- - bundle install
24
-
25
- bundler_args: --no-deployment --jobs 3 --retry 3
26
+ - bundle install --path=${BUNDLE_PATH:-vendor/bundle} --no-deployment --jobs 3 --retry 3
26
27
 
27
- language: ruby
28
- cache: bundler
29
- rvm:
30
- - 2.3.7
31
- - 2.4.4
32
- - 2.5.1
28
+ jobs:
29
+ include:
30
+ - rvm: ruby-2.3.8
31
+ gemfile: gemfiles/ruby_2.3.gemfile
32
+ - rvm: ruby-2.4.9
33
+ gemfile: gemfiles/ruby_2.4.gemfile
34
+ - rvm: ruby-2.5.7
35
+ gemfile: gemfiles/ruby_2.5.gemfile
36
+ - rvm: ruby-2.6.5
37
+ gemfile: gemfiles/ruby_2.6.gemfile
38
+ - rvm: ruby-2.7.0
39
+ gemfile: gemfiles/ruby_2.7.gemfile
@@ -0,0 +1,24 @@
1
+ appraise "ruby_2.3" do
2
+ gem "rubocop", "0.77.0"
3
+ gem 'rubocop-minitest'
4
+ end
5
+
6
+ appraise "ruby_2.4" do
7
+ gem "rubocop", "0.77.0"
8
+ gem 'rubocop-minitest'
9
+ end
10
+
11
+ appraise "ruby_2.5" do
12
+ gem "rubocop"
13
+ gem 'rubocop-minitest'
14
+ end
15
+
16
+ appraise "ruby_2.6" do
17
+ gem "rubocop"
18
+ gem 'rubocop-minitest'
19
+ end
20
+
21
+ appraise "ruby_2.7" do
22
+ gem "rubocop"
23
+ gem 'rubocop-minitest'
24
+ end
data/README.md CHANGED
@@ -4,11 +4,12 @@ SilentStream is an extraction of some parts of ActiveSupport's Kernel Reporting
4
4
 
5
5
  Since July 2014 `silence_stream`, `silence_stderr`, `capture`, `silence`, and `quietly` have been deprecated because they are not thread safe. See that discussion in the [PR where it all went down](https://github.com/rails/rails/pull/13392). I rely on them a lot in *single threaded* code, and so I plan to keep them alive. With the exception of `silence`, which was just an alias of `capture`.
6
6
 
7
- This gem was taken out of Rails but it is *not* Rails dependent. The extraction was total (**even the tests**!), and this is now a pure Ruby library, which can be used in any Ruby project without encumbrances.
7
+ This gem was taken out of Rails but it is *not* Rails dependent. The extraction was total (**even the tests**!), and this is now a pure Ruby library, which can be used in any Ruby project without encumbrances. *This gem has no runtime dependencies*.
8
8
 
9
9
  | Project | SilentStream |
10
10
  |------------------------ | ----------------------- |
11
11
  | gem name | [silent_stream](https://rubygems.org/gems/silent_stream) |
12
+ | compatibility | Ruby 2.3, 2.4, 2.5, 2.6, 2.7 |
12
13
  | license | [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) |
13
14
  | download rank | [![Downloads Today](https://img.shields.io/gem/rd/silent_stream.svg)](https://github.com/pboling/silent_stream) |
14
15
  | version | [![Version](https://img.shields.io/gem/v/silent_stream.svg)](https://rubygems.org/gems/silent_stream) |
@@ -47,11 +48,33 @@ Or install it yourself as:
47
48
 
48
49
  ## Usage
49
50
 
50
- Usage:
51
+ Four standard methods you may be familiar with from ActiveSupport's previous implementation are provided:
52
+
53
+ ```
54
+ silence_stderr
55
+ silence_stream
56
+ capture
57
+ quietly
58
+ ```
59
+
60
+ They are direct replicas, *except* not mixed into `Kernel` or `Object`, so in order to use them you must mix them into your classes or modules.
61
+
62
+ ```
63
+ class Bogosity
64
+ include SilentStream::Extracted # allows use at instance level
65
+ extend SilentStream::Extracted # allows use at class level
66
+ # or
67
+ include SilentStream # access everything, and add #silence_all method, see below
68
+ end
69
+ ```
70
+
71
+ In addition there is a `silence_all` method that is a useful wrapper that can be easily instrumented (turned off and on) with an ENV variable switch.
72
+
73
+ Including the `SilentStream` namespace fully gives access to this enhanced method, as well as the extracted methods above, and also makes everything available at the class and instance levels.
51
74
 
52
75
  ```ruby
53
76
  class Bogosity
54
- include SilentStream # allows use at instance or class level
77
+ include SilentStream # allows use of any method at instance or class level
55
78
 
56
79
  def silent
57
80
  silence_all(true) do
@@ -69,7 +92,9 @@ class Bogosity
69
92
  end
70
93
  end
71
94
  ```
95
+
72
96
  And run
97
+
73
98
  ```
74
99
  >> Bogosity.new.silent # has no output
75
100
  => nil
@@ -78,6 +103,29 @@ play that funky music
78
103
  => nil
79
104
  ```
80
105
 
106
+ ## Use in Specs / Tests
107
+
108
+ Make the methods avaialble:
109
+ ```
110
+ RSpec.configure do |conf|
111
+ conf.include SilentStream
112
+ end
113
+ ```
114
+
115
+ Then add a test on output:
116
+ ```
117
+ it 'has output' do
118
+ output = capture(:stdout) { subject.request(:get, '/success') }
119
+ logs = [
120
+ 'INFO -- request: GET https://api.example.com/success',
121
+ 'INFO -- response: Status 200'
122
+ ]
123
+ expect(output).to include(*logs)
124
+ end
125
+ ```
126
+
127
+ See it in practice in the [specs for the oauth2 gem](https://github.com/oauth-xx/oauth2/blob/master/spec/oauth2/client_spec.rb#L193)
128
+
81
129
  ## Development
82
130
 
83
131
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "0.77.0"
6
+ gem "rubocop-minitest"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop", "0.77.0"
6
+ gem "rubocop-minitest"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop"
6
+ gem "rubocop-minitest"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop"
6
+ gem "rubocop-minitest"
7
+
8
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rubocop"
6
+ gem "rubocop-minitest"
7
+
8
+ gemspec path: "../"
@@ -23,26 +23,44 @@ module SilentStream
23
23
  #
24
24
  # This method is not thread-safe.
25
25
  def silence_all(switch = true, temporary_level = Logger::ERROR, logger = nil)
26
- if !switch || ENV['NO_SILENCE'] == 'true'
26
+ if !switch || silent_stream_no_silence
27
27
  yield
28
28
  else
29
29
  begin
30
- logger ||= defined?(Rails) ? Rails.logger : nil
31
- logger && (old_logger_level = logger.level || true) && (logger.level = temporary_level)
30
+ logger ||= silent_stream_logger
31
+ old_logger_level = silent_stream_reset_logger_level(logger, temporary_level)
32
32
  # silence STDOUT (like puts)
33
33
  silence_stream(STDOUT) do
34
34
  yield
35
35
  end
36
36
  ensure
37
- logger && (logger.level = old_logger_level)
37
+ silent_stream_reset_logger_level(logger, old_logger_level)
38
38
  end
39
39
  end
40
40
  end
41
+
42
+ private
43
+
44
+ def silent_stream_no_silence
45
+ ENV['NO_SILENCE'] == 'true'
46
+ end
47
+
48
+ def silent_stream_logger
49
+ defined?(Rails) ? Rails.logger : nil
50
+ end
51
+
52
+ # returns previous logger's level
53
+ def silent_stream_reset_logger_level(logger, temporary_level)
54
+ logger && (old_logger_level = logger.level || true) && (logger.level = temporary_level)
55
+ old_logger_level
56
+ end
41
57
  end
42
58
 
43
59
  # Extracted from:
44
60
  # https://github.com/rails/rails/blob/4-2-stable/activesupport/lib/active_support/core_ext/kernel/reporting.rb
45
61
  module Extracted
62
+ SILENT_STREAM_NULL_DEVICE = defined?(IO::NULL) ? IO::NULL : Gem.win_platform? ? 'NUL:' : '/dev/null'
63
+
46
64
  # This method is not thread-safe.
47
65
  def silence_stderr
48
66
  silence_stream(STDERR) { yield }
@@ -59,7 +77,11 @@ module SilentStream
59
77
  # This method is not thread-safe.
60
78
  def silence_stream(stream)
61
79
  old_stream = stream.dup
62
- stream.reopen(windows_os_test ? 'NUL:' : '/dev/null')
80
+ begin
81
+ stream.reopen(SILENT_STREAM_NULL_DEVICE, 'a+')
82
+ rescue Exception => e
83
+ stream.puts "[SilentStream] Unable to silence. #{e.class}: #{e.message}"
84
+ end
63
85
  stream.sync = true
64
86
  yield
65
87
  ensure
@@ -119,15 +141,15 @@ module SilentStream
119
141
 
120
142
  private
121
143
 
122
- WINDOWS_REGEXP = /mswin|mingw/
123
- REGEXP_HAS_MATCH = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4')
144
+ SILENT_STREAM_WINDOWS_REGEXP = /mswin|mingw/.freeze
145
+ SILENT_STREAM_REGEXP_HAS_MATCH = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4')
124
146
  def windows_os_test
125
147
  # When available, in Ruby 2.4+, we use Regexp#match? which does not update
126
148
  # the $~ global object and may be 3x faster than alternative match tests
127
- if REGEXP_HAS_MATCH
128
- WINDOWS_REGEXP.match?(RbConfig::CONFIG['host_os'])
149
+ if SILENT_STREAM_REGEXP_HAS_MATCH
150
+ SILENT_STREAM_WINDOWS_REGEXP.match?(RbConfig::CONFIG['host_os'])
129
151
  else
130
- WINDOWS_REGEXP =~ (RbConfig::CONFIG['host_os'])
152
+ SILENT_STREAM_WINDOWS_REGEXP =~ (RbConfig::CONFIG['host_os'])
131
153
  end
132
154
  end
133
155
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SilentStream
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
@@ -55,15 +55,13 @@ Gem::Specification.new do |spec|
55
55
  spec.require_paths = ['lib']
56
56
  spec.license = 'MIT'
57
57
 
58
- if RUBY_VERSION < '1.9.3'
59
- spec.add_development_dependency 'rake', '>= 10.4'
60
- else
61
- spec.add_development_dependency 'rake'
62
- end
63
- spec.add_development_dependency 'bundler', '~> 1.16'
64
- spec.add_development_dependency 'minitest', '~> 5.10'
58
+ spec.add_development_dependency 'rake'
59
+ spec.add_development_dependency 'appraisal'
60
+ spec.add_development_dependency 'bundler'
61
+ spec.add_development_dependency 'minitest', '>= 5.10'
65
62
  spec.add_development_dependency 'minitest-reporters'
66
63
  spec.add_development_dependency 'mocha'
67
- spec.add_development_dependency 'simplecov', '~> 0.16'
68
- spec.add_development_dependency 'test-unit', '~> 3.2'
64
+ spec.add_development_dependency 'simplecov', '>= 0.16'
65
+ spec.add_development_dependency 'test-unit', '>= 3.2'
66
+ spec.add_development_dependency 'wwtd'
69
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silent_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Daer
@@ -33,7 +33,7 @@ authors:
33
33
  autorequire:
34
34
  bindir: exe
35
35
  cert_chain: []
36
- date: 2018-10-10 00:00:00.000000000 Z
36
+ date: 2020-02-25 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rake
@@ -49,32 +49,46 @@ dependencies:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
+ - !ruby/object:Gem::Dependency
53
+ name: appraisal
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ type: :development
60
+ prerelease: false
61
+ version_requirements: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
52
66
  - !ruby/object:Gem::Dependency
53
67
  name: bundler
54
68
  requirement: !ruby/object:Gem::Requirement
55
69
  requirements:
56
- - - "~>"
70
+ - - ">="
57
71
  - !ruby/object:Gem::Version
58
- version: '1.16'
72
+ version: '0'
59
73
  type: :development
60
74
  prerelease: false
61
75
  version_requirements: !ruby/object:Gem::Requirement
62
76
  requirements:
63
- - - "~>"
77
+ - - ">="
64
78
  - !ruby/object:Gem::Version
65
- version: '1.16'
79
+ version: '0'
66
80
  - !ruby/object:Gem::Dependency
67
81
  name: minitest
68
82
  requirement: !ruby/object:Gem::Requirement
69
83
  requirements:
70
- - - "~>"
84
+ - - ">="
71
85
  - !ruby/object:Gem::Version
72
86
  version: '5.10'
73
87
  type: :development
74
88
  prerelease: false
75
89
  version_requirements: !ruby/object:Gem::Requirement
76
90
  requirements:
77
- - - "~>"
91
+ - - ">="
78
92
  - !ruby/object:Gem::Version
79
93
  version: '5.10'
80
94
  - !ruby/object:Gem::Dependency
@@ -109,30 +123,44 @@ dependencies:
109
123
  name: simplecov
110
124
  requirement: !ruby/object:Gem::Requirement
111
125
  requirements:
112
- - - "~>"
126
+ - - ">="
113
127
  - !ruby/object:Gem::Version
114
128
  version: '0.16'
115
129
  type: :development
116
130
  prerelease: false
117
131
  version_requirements: !ruby/object:Gem::Requirement
118
132
  requirements:
119
- - - "~>"
133
+ - - ">="
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0.16'
122
136
  - !ruby/object:Gem::Dependency
123
137
  name: test-unit
124
138
  requirement: !ruby/object:Gem::Requirement
125
139
  requirements:
126
- - - "~>"
140
+ - - ">="
127
141
  - !ruby/object:Gem::Version
128
142
  version: '3.2'
129
143
  type: :development
130
144
  prerelease: false
131
145
  version_requirements: !ruby/object:Gem::Requirement
132
146
  requirements:
133
- - - "~>"
147
+ - - ">="
134
148
  - !ruby/object:Gem::Version
135
149
  version: '3.2'
150
+ - !ruby/object:Gem::Dependency
151
+ name: wwtd
152
+ requirement: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ type: :development
158
+ prerelease: false
159
+ version_requirements: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
136
164
  description: ActiveSupport Kernel Reporting Detritus with a few enhancements
137
165
  email:
138
166
  - peter.boling@gmail.com
@@ -144,6 +172,7 @@ files:
144
172
  - ".rubocop.yml"
145
173
  - ".ruby-version"
146
174
  - ".travis.yml"
175
+ - Appraisals
147
176
  - CODE_OF_CONDUCT.md
148
177
  - Gemfile
149
178
  - LICENSE
@@ -151,6 +180,11 @@ files:
151
180
  - Rakefile
152
181
  - bin/console
153
182
  - bin/setup
183
+ - gemfiles/ruby_2.3.gemfile
184
+ - gemfiles/ruby_2.4.gemfile
185
+ - gemfiles/ruby_2.5.gemfile
186
+ - gemfiles/ruby_2.6.gemfile
187
+ - gemfiles/ruby_2.7.gemfile
154
188
  - lib/silent_stream.rb
155
189
  - lib/silent_stream/version.rb
156
190
  - silent_stream.gemspec
@@ -173,8 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
207
  - !ruby/object:Gem::Version
174
208
  version: '0'
175
209
  requirements: []
176
- rubyforge_project:
177
- rubygems_version: 2.7.7
210
+ rubygems_version: 3.1.2
178
211
  signing_key:
179
212
  specification_version: 4
180
213
  summary: ActiveSupport's Stream Silencing - Without ActiveSupport