Module: RakeCommander::Patcher::Debug

Included in:
Application::TopLevelResume::ClassMethods
Defined in:
lib/rake-commander/patcher/debug.rb

Overview

Helpers to patch

Instance Method Summary collapse

Instance Method Details

#rake_comm_debug(msg, prefix = '', num: nil, pid: false) ⇒ Object

Helper for debugging



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/rake-commander/patcher/debug.rb', line 6

def rake_comm_debug(msg, prefix = '', num: nil, pid: false)
  return unless RakeCommander::Patcher.debug?
  rake_comm_debug_random_object_id
  num = num ? "#{num}. " : nil
  if pid
    meta = "(PID: #{Process.pid} ++ Thread: #{Thread.current.object_id} ++ Ruby 'main': #{rake_comm_debug_main_object_id})"
    msg  = "#{prefix}( #{num}#{Rake.application.object_id})   #{msg}   #{meta}"
  elsif num
    msg  = "#{prefix}( #{num})   #{msg}   "
  end
  puts msg
end

#rake_comm_debug_main_object_idObject



19
20
21
# File 'lib/rake-commander/patcher/debug.rb', line 19

def rake_comm_debug_main_object_id
  eval('self.object_id', TOPLEVEL_BINDING, __FILE__, __LINE__)
end

#rake_comm_debug_random_object_idObject



23
24
25
26
27
28
29
# File 'lib/rake-commander/patcher/debug.rb', line 23

def rake_comm_debug_random_object_id
  return false if @rake_comm_debug_random_object_id
  @rake_comm_debug_random_object_id = Array(1..20).sample.times.map do |i|
    i.to_s.tap(&:object_id)
  end
  true
end