Sha256: c79acaedff0538e9f72fe5d48d639ba7ec70053ab0c4a56d58b6417df18f2b46

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 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
  @@colorize_enabled = true   # Default to enabled
  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 & 2 rubygems

Version Path
quality_extensions-0.1.1 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.60 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.64 lib/qualitysmith_extensions/colored/toggleability.rb
qualitysmith_extensions-0.0.63 lib/qualitysmith_extensions/colored/toggleability.rb