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
- .calling_method ⇒ Object
- .enabled ⇒ Object
- .enabled=(enabled) ⇒ Object
- .expression_string(binding, *expressions) ⇒ Object
- .format_expression(binding, expression) ⇒ Object
- .format_value(value) ⇒ Object
- .log(binding, comment, *expressions) ⇒ Object
- .logger ⇒ Object
- .logger=(logger) ⇒ Object
- .prefix ⇒ Object
- .separator ⇒ Object
- .stdout ⇒ Object
- .stdout=(stdout) ⇒ Object
Class Method Details
.calling_method ⇒ Object
43 44 45 |
# File 'lib/debug_log.rb', line 43 def self.calling_method Kernel.caller(3).first end |
.enabled ⇒ Object
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 = [prefix, comment, expression_string(binding, *expressions), calling_method].join(separator) puts() if stdout logger.call() if logger end |
.logger ⇒ Object
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 |
.prefix ⇒ Object
24 25 26 |
# File 'lib/debug_log.rb', line 24 def self.prefix name end |
.separator ⇒ Object
28 29 30 |
# File 'lib/debug_log.rb', line 28 def self.separator " | " end |
.stdout ⇒ Object
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 |