Module: DebugLog

Defined in:
lib/debug_log.rb,
lib/debug_log/version.rb

Constant Summary collapse

VERSION =
"0.1.0"
@@logger =
nil
@@stdout =
true
@@enabled =
true

Class Method Summary collapse

Class Method Details

.calling_methodObject



43
44
45
# File 'lib/debug_log.rb', line 43

def self.calling_method
  Kernel.caller(3).first
end

.enabledObject



21
# File 'lib/debug_log.rb', line 21

def self.enabled; @@enabled; end

.enabled=(enabled) ⇒ Object



22
# File 'lib/debug_log.rb', line 22

def self.enabled=(enabled); @@enabled = enabled; end

.expression_string(binding, *expressions) ⇒ Object



39
40
41
# File 'lib/debug_log.rb', line 39

def self.expression_string(binding, *expressions)
  expressions.map { |expression| format_expression(binding, expression) }.join(", ")
end

.format_expression(binding, expression) ⇒ Object



51
52
53
54
# File 'lib/debug_log.rb', line 51

def self.format_expression(binding, expression)
  value = eval(expression, binding)
  %Q{#{expression}="#{format_value(value)}" (#{value.class.name})}
end

.format_value(value) ⇒ Object



47
48
49
# File 'lib/debug_log.rb', line 47

def self.format_value(value)
  value.inspect
end

.log(binding, comment, *expressions) ⇒ Object



32
33
34
35
36
37
# File 'lib/debug_log.rb', line 32

def self.log(binding, comment, *expressions)
  return unless enabled
  message = [prefix, comment, expression_string(binding, *expressions), calling_method].join(separator)
  puts(message) if stdout
  logger.call(message) if logger
end

.loggerObject



13
# File 'lib/debug_log.rb', line 13

def self.logger; @@logger; end

.logger=(logger) ⇒ Object



14
# File 'lib/debug_log.rb', line 14

def self.logger=(logger); @@logger = logger; end

.prefixObject



24
25
26
# File 'lib/debug_log.rb', line 24

def self.prefix
  name
end

.separatorObject



28
29
30
# File 'lib/debug_log.rb', line 28

def self.separator
  " | "
end

.stdoutObject



17
# File 'lib/debug_log.rb', line 17

def self.stdout; @@stdout; end

.stdout=(stdout) ⇒ Object



18
# File 'lib/debug_log.rb', line 18

def self.stdout=(stdout); @@stdout = stdout; end