Class: Rreplay::Debugger

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

Instance Method Summary collapse

Constructor Details

#initialize(logger, debug = true) ⇒ Debugger

Returns a new instance of Debugger.



3
4
5
6
# File 'lib/rreplay/debugger.rb', line 3

def initialize(logger, debug = true)
  @logger = logger
  @debug = !logger.nil? && debug
end

Instance Method Details

#out(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rreplay/debugger.rb', line 8

def out(&block)
  return unless @debug

  msg = block.call.then do |msg|
    case msg
    when Hash
      msg.merge({ time: Time.now.iso8601 }).to_json
    else
      "#{Time.now.iso8601} - #{block.call}"
    end
  end
  @logger.write("#{msg}\n")
end