Exception: Exception

Defined in:
lib/razing_ruby/exception.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#call_bindingObject (readonly)

Returns the value of attribute call_binding.



4
5
6
# File 'lib/razing_ruby/exception.rb', line 4

def call_binding
  @call_binding
end

Instance Method Details

#call_variablesObject



35
36
37
# File 'lib/razing_ruby/exception.rb', line 35

def call_variables
  eval('local_variables.reduce({}) { |o, l| o.merge(l => eval("#{l}")) }', call_binding)
end

#raze_initialize(*a, &b) ⇒ Object Also known as: initialize



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/razing_ruby/exception.rb', line 6

def raze_initialize(*a, &b)
  # Find the calling location
  expected_file, expected_line = caller(1).first.split(':')[0,2]
  expected_line = expected_line.to_i
  return_count = 5  # If we see more than 5 returns, stop tracing

  # Find our caller in the midst of the trace
  find_binding = Proc.new do |event, file, line, id, binding, kls|
    if file == expected_file && line == expected_line
      # Found it: Save the binding and stop tracing
      @call_binding = binding
      unset_trace_func(find_binding)
    end

    if event == :return
      # Seen too many returns, give up. :-(
      unset_trace_func(find_binding) if (return_count -= 1) <= 0
    end
  end

  # Start tracing until we see our caller.
  set_trace_func(find_binding)
  ruby_initialize(*a, &b)
  set_backtrace(caller(3))

  # Hitup our exception handlers
  Kernel.raze_raise_funcs.each { |p| p.call(self) }
end