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.1.11 lib/softcover/output.rb
softcover-1.1.10 lib/softcover/output.rb
softcover-1.1.9 lib/softcover/output.rb
softcover-1.1.8 lib/softcover/output.rb
softcover-1.1.7 lib/softcover/output.rb
softcover-1.1.6 lib/softcover/output.rb
softcover-1.1.4 lib/softcover/output.rb
softcover-1.1.3 lib/softcover/output.rb
softcover-1.1.2 lib/softcover/output.rb
softcover-1.1.1 lib/softcover/output.rb
softcover-1.1.0 lib/softcover/output.rb
softcover-1.1.beta2 lib/softcover/output.rb
softcover-1.0.5 lib/softcover/output.rb
softcover-1.1.beta1 lib/softcover/output.rb
softcover-1.0.4 lib/softcover/output.rb
softcover-1.0.3 lib/softcover/output.rb
softcover-1.0.2 lib/softcover/output.rb
softcover-1.0.1 lib/softcover/output.rb
softcover-1.0.0 lib/softcover/output.rb
softcover-1.0.beta17 lib/softcover/output.rb