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.2.5 lib/softcover/output.rb
softcover-1.2.4 lib/softcover/output.rb
softcover-1.2.3 lib/softcover/output.rb
softcover-1.2.2 lib/softcover/output.rb
softcover-1.2.1 lib/softcover/output.rb
softcover-1.2.0 lib/softcover/output.rb
softcover-1.1.28 lib/softcover/output.rb
softcover-1.1.27 lib/softcover/output.rb
softcover-1.1.23 lib/softcover/output.rb
softcover-1.1.22 lib/softcover/output.rb
softcover-1.1.21 lib/softcover/output.rb
softcover-1.1.20 lib/softcover/output.rb
softcover-1.1.19 lib/softcover/output.rb
softcover-1.1.18 lib/softcover/output.rb
softcover-1.1.17 lib/softcover/output.rb
softcover-1.1.16 lib/softcover/output.rb
softcover-1.1.15 lib/softcover/output.rb
softcover-1.1.14 lib/softcover/output.rb
softcover-1.1.13 lib/softcover/output.rb
softcover-1.1.12 lib/softcover/output.rb