Class: AlertMachine::Caller
- Inherits:
-
Object
- Object
- AlertMachine::Caller
- Defined in:
- lib/alert_machine.rb
Overview
Figures out how to parse the call stack and pretty print it.
Instance Attribute Summary collapse
-
#caller ⇒ Object
readonly
Returns the value of attribute caller.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
Instance Method Summary collapse
- #file_line ⇒ Object
-
#initialize(caller, &block) ⇒ Caller
constructor
A new instance of Caller.
- #log ⇒ Object
- #log_source_file ⇒ Object
Constructor Details
#initialize(caller, &block) ⇒ Caller
Returns a new instance of Caller.
115 116 117 118 119 120 |
# File 'lib/alert_machine.rb', line 115 def initialize(caller, &block) @block = block if block_given? @caller = caller /^(?<fname>[^:]+)\:(?<line>\d+)\:/ =~ caller[0] and @file = fname and @line = line end |
Instance Attribute Details
#caller ⇒ Object (readonly)
Returns the value of attribute caller.
113 114 115 |
# File 'lib/alert_machine.rb', line 113 def caller @caller end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
113 114 115 |
# File 'lib/alert_machine.rb', line 113 def file @file end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
113 114 115 |
# File 'lib/alert_machine.rb', line 113 def line @line end |
Instance Method Details
#file_line ⇒ Object
122 123 124 |
# File 'lib/alert_machine.rb', line 122 def file_line "#{file}:#{line}" end |
#log ⇒ Object
126 127 128 129 |
# File 'lib/alert_machine.rb', line 126 def log "#{caller[0]}\n" + log_source_file.to_s end |
#log_source_file ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/alert_machine.rb', line 131 def log_source_file File.open(file) {|fh| fh.readlines[line.to_i - 1..line.to_i + 3].collect {|l| ">> #{l}" }.join + "\n---\n" } if file && File.exists?(file) end |