Class: SeeingIsBelieving::Debugger

Inherits:
Object
  • Object
show all
Defined in:
lib/seeing_is_believing/debugger.rb

Constant Summary collapse

CONTEXT_COLOUR =
"\e[37;44m"
RESET_COLOUR =
"\e[0m"

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Debugger

Returns a new instance of Debugger.



7
8
9
10
11
# File 'lib/seeing_is_believing/debugger.rb', line 7

def initialize(options={})
  @contexts = Hash.new { |h, k| h[k] = [] }
  @enabled  = options.fetch :enabled, true
  @coloured = options.fetch :colour,  false
end

Instance Method Details

#coloured?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/seeing_is_believing/debugger.rb', line 17

def coloured?
  @coloured
end

#context(name, &block) ⇒ Object



21
22
23
24
# File 'lib/seeing_is_believing/debugger.rb', line 21

def context(name, &block)
  @contexts[name] << block.call if enabled?
  self
end

#enabled?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/seeing_is_believing/debugger.rb', line 13

def enabled?
  @enabled
end

#to_sObject



26
27
28
29
30
31
32
33
34
# File 'lib/seeing_is_believing/debugger.rb', line 26

def to_s
  @contexts.map { |name, values|
    string = ""
    string << CONTEXT_COLOUR if coloured?
    string << "#{name}:"
    string << RESET_COLOUR if coloured?
    string << "\n#{values.join "\n"}\n"
  }.join("\n")
end