Sha256: d8aae67262583afa9b4159ba726a296d97ed6b267d7b739863e65e2676f20f78

Contents?: true

Size: 778 Bytes

Versions: 173

Compression:

Stored size: 778 Bytes

Contents

module Softcover::Output
  class << self
    attr_accessor :silent, :stream, :verbosity_level

    def stream
      silent? ? StringIO.new : (defined?(@stream) && @stream) || $stdout
    end

    def silence!
      @silent = true
    end

    def unsilence!
      @silent = false
    end

    def silent?
      defined?(@silent) && @silent
    end

    def should_output?(level)
      !silent? ||
      !(level && defined?(@verbosity_level) && level < @verbosity_level)
    end
  end

  %w{puts printf print}.each do |method|
    define_method method do |string, options={}|
      if Softcover::Output.should_output?(options[:level])
        Softcover::Output.stream.send method, string
      end
    end
  end

  def system(cmd)
    output = `#{cmd}`
    puts output
  end
end

Version data entries

173 entries across 173 versions & 2 rubygems

Version Path
softcover-1.10.5 lib/softcover/output.rb
softcover-1.10.4 lib/softcover/output.rb
softcover-1.10.3 lib/softcover/output.rb
softcover-1.10.2 lib/softcover/output.rb
softcover-1.10.1 lib/softcover/output.rb
softcover-1.10.0 lib/softcover/output.rb
softcover-1.9.1 lib/softcover/output.rb
softcover-1.9.0 lib/softcover/output.rb
softcover-1.8.3 lib/softcover/output.rb
softcover-1.8.2 lib/softcover/output.rb
softcover-1.8.1 lib/softcover/output.rb
softcover-1.8.0 lib/softcover/output.rb
softcover-1.7.5 lib/softcover/output.rb
softcover-1.7.4 lib/softcover/output.rb
softcover-1.7.3 lib/softcover/output.rb
softcover-1.7.2 lib/softcover/output.rb
softcover-1.7.1 lib/softcover/output.rb
softcover-1.7.0 lib/softcover/output.rb
softcover-1.6.5 lib/softcover/output.rb
softcover-1.6.4 lib/softcover/output.rb