SilentStream is an extraction of some parts of ActiveSupport's Kernel Reporting Core Extentions around silencing IO streams.
Since July 2014
quietly have been deprecated because they are not thread safe. See that discussion in the PR where it all went down. 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
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.
|homepage||on Github.com, on Railsbling.com|
One aspect of what this gem provides can be achieved with the Rails' built-in
LoggerSilence, which is thread safe. You will have to decide what is right for you!
Doing a Rails <= 4 to Rails >= 5 Upgrade?
The reason for not keeping
silence as it was in Rails 4, i.e. an alias of
capture, is that the just mentioned
LoggerSilence now uses this term, and it is shipping with Rails 5. I don't want to make this gem incompatible with Rails 5, so you will have to convert Rails <= 4 implementations that utilize
silence over to
capture when using this gem. One further point of difference is this gem does not add the methods to
Object. You can do that if you like via
include. By default this gem does not pollute anything, so you will need to
include SilentStream in any class using these methods.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install silent_stream
Four standard methods you may be familiar with from ActiveSupport's previous implementation are provided:
silence_stderr silence_stream capture quietly
They are direct replicas, except not mixed into
Object, so in order to use them you must mix them into your classes or modules.
class Bogosity include SilentStream::Extracted # allows use at instance level include SilentStream::Extracted # allows use at class level end
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.
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.
class Bogosity include SilentStream # allows use of any method at instance or class level def silent silence_all(true) do puts "play that funky music" Rails.logger.info "git jiggy with it" end end class << self def noise silence_all(false) do puts "play that funky music" Rails.logger.info "git jiggy with it" end end end end
>> Bogosity.new.silent # has no output => nil >> Bogosity.noise # is noisy play that funky music => nil
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.
To install this gem onto your local machine, run
bundle exec rake install. To release a new version, update the version number in
version.rb, and then run
bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the
.gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/silent_stream.
Code of Conduct
Everyone interacting in the AnonymousActiveRecord project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
This library aims to adhere to Semantic Versioning 2.0.0. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions.
As a result of this policy, you can (and should) specify a dependency on this gem using the Pessimistic Version Constraint with two digits of precision.
spec.add_dependency 'silent_stream', '~> 1.0'