Sha256: 49b945210f3419a6ade8866c251b04a9f036da2f60f6ce28257e9e5b8f60d2ba

Contents?: true

Size: 821 Bytes

Versions: 26

Compression:

Stored size: 821 Bytes

Contents

# From ActiveSupport: https://github.com/rails/rails/blob/c2c8ef57d6f00d1c22743dc43746f95704d67a95/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L39

require 'rbconfig'

module Kernel
  # Silences any stream for the duration of the block.
  #
  #   silence_stream(STDOUT) do
  #     puts 'This will never be seen'
  #   end
  #
  #   puts 'But this will'
  def silence_stream(stream)
    old_stream = stream.dup
    stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
    stream.sync = true
    yield
  ensure
    stream.reopen(old_stream)
  end

  # Silences both STDOUT and STDERR, even for subprocesses.
  #
  #   quietly { system 'bundle install' }
  #
  def quietly
    silence_stream(STDOUT) do
      silence_stream(STDERR) do
        yield
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
nexus_cli-0.1.2 lib/nexus_cli/kernel.rb
nexus_cli-0.1.1 lib/nexus_cli/kernel.rb
nexus_cli-0.1.0 lib/nexus_cli/kernel.rb
nexus_cli-0.0.5 lib/nexus_cli/kernel.rb
nexus_cli-0.0.4 lib/nexus_cli/kernel.rb
nexus_cli-0.0.3 lib/nexus_cli/kernel.rb