Sha256: 90d7fc444269904650000407710e4694d2b8dbc04c0dc27ecaaafb340457aaab

Contents?: true

Size: 822 Bytes

Versions: 22

Compression:

Stored size: 822 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

22 entries across 22 versions & 4 rubygems

Version Path
knife_cookbook_dependencies_over_http-0.0.8 lib/kcd/core_ext/kernel.rb
knife_cookbook_dependencies-0.0.8 lib/kcd/core_ext/kernel.rb