Sha256: 589ae39f768b66f024927d54d8ddb1bc8bcd7d3b84587315fb25ce7d2135b7d9

Contents?: true

Size: 865 Bytes

Versions: 11

Compression:

Stored size: 865 Bytes

Contents

module CanTango
  class Configuration
    # Note: This config feature is currently not used, but could potentially be of use in the future
    class Debug
      include Singleton

      def set state = :on
        raise ArgumentError, "Must be :on or :off" unless !state || [:on, :off].include?(state)
        @state = state || :on
      end

      def on?
        @state == :on
      end

      def off?
        !on?
      end
      
      def debug_writer= proc
        raise ArgumentError, "Debug writer must be callable (lambda or Proc), was: #{proc}" if !callable?(proc)
        @debug_writer = proc
      end
      
      def write msg
        @debug_writer ||= Proc.new{|msg| puts msg}
        @debug_writer.call(msg)
      end
      
      protected
      
      def callable? obj
        obj && obj.respond_to?(:call)
      end      
    end
  end
end




Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cantango-config-0.1.9.2 lib/cantango/configuration/debug.rb
cantango-config-0.1.8.1 lib/cantango/configuration/debug.rb
cantango-config-0.1.8 lib/cantango/configuration/debug.rb
cantango-config-0.1.7 lib/cantango/configuration/debug.rb
cantango-config-0.1.6 lib/cantango/configuration/debug.rb
cantango-config-0.1.5 lib/cantango/configuration/debug.rb
cantango-config-0.1.4 lib/cantango/configuration/debug.rb
cantango-config-0.1.3 lib/cantango/configuration/debug.rb
cantango-config-0.1.2 lib/cantango/configuration/debug.rb
cantango-config-0.1.1 lib/cantango/configuration/debug.rb
cantango-config-0.1.0 lib/cantango/configuration/debug.rb