Class: SeeingIsBelieving::Debugger
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Debugger
- Defined in:
- lib/seeing_is_believing/debugger.rb
Constant Summary collapse
- CONTEXT_COLOUR =
"\e[37;44m"
- RESET_COLOUR =
"\e[0m"
Instance Method Summary collapse
- #coloured? ⇒ Boolean
- #context(name, &block) ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(options = {}) ⇒ Debugger
constructor
A new instance of Debugger.
- #to_s ⇒ Object
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(={}) @contexts = Hash.new { |h, k| h[k] = [] } @enabled = .fetch :enabled, true @coloured = .fetch :colour, false end |
Instance Method Details
#coloured? ⇒ 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
13 14 15 |
# File 'lib/seeing_is_believing/debugger.rb', line 13 def enabled? @enabled end |
#to_s ⇒ Object
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 |