Sha256: d8267334739301ea9a4a042542b25bd1540fa04444f53a21857fbb5b8490a38f

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

#--
# Author::    Tyler Rick
# Copyright:: Copyright (c) 2007 QualitySmith, Inc.
# License::   Ruby License
# Submit to Facets?::
# Developer notes::
#++

require 'rubygems'
gem 'colored'
require 'colored'
gem 'facets'
require 'facets/core/module/alias_method_chain'
gem 'qualitysmith_extensions'
require 'qualitysmith_extensions/module/guard_method'

class String
  def colorize_with_toggleability(string, options = {})
    if @@colorize_enabled
      colorize_without_toggleability(string, options)
    else
      string
    end
  end
  alias_method_chain :colorize, :toggleability
  mguard_method :color_on!, :@@colorize_enabled

end unless String.instance_methods.include?('colorize_with_toggleability')


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test
require 'test/unit'

class TheTest < Test::Unit::TestCase
  def test_color_on
    String.color_on!
    assert_equal "\e[31mfoo\e[0m", 'foo'.red
  end
  def test_color_off
    String.color_on! false
    assert_equal "foo", 'foo'.red
  end
  def test_color_off_with_block
    String.color_on!
    assert_equal "\e[31mfoo\e[0m", 'foo'.red
    String.color_on! false do
      assert_equal "foo", 'foo'.red
    end
    assert_equal "\e[31mfoo\e[0m", 'foo'.red
  end

end
=end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
qualitysmith_extensions-0.0.33 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.34 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.29 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.49 lib/qualitysmith_extensions/colored/toggleability.rb