Class: PryStackExplorer::WhenStartedHook

Inherits:
Object
  • Object
show all
Includes:
Pry::Helpers::BaseHelpers
Defined in:
lib/pry-stack_explorer/when_started_hook.rb

Instance Method Summary collapse

Instance Method Details

#call(target, options, _pry_) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pry-stack_explorer/when_started_hook.rb', line 23

def call(target, options, _pry_)
  target ||= _pry_.binding_stack.first if _pry_
  options = {
    :call_stack    => true,
    :initial_frame => 0
  }.merge!(options)

  return if !options[:call_stack]

  if options[:call_stack].is_a?(Array)
    bindings = options[:call_stack]

    if !valid_call_stack?(bindings)
      raise ArgumentError, ":call_stack must be an array of bindings"
    end
  else
    bindings = caller_bindings(target)
  end

  PryStackExplorer.create_and_push_frame_manager bindings, _pry_, :initial_frame => options[:initial_frame]
end

#caller_bindings(target) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pry-stack_explorer/when_started_hook.rb', line 5

def caller_bindings(target)
  bindings = binding.callers

  bindings = remove_internal_frames(bindings)
  bindings = remove_debugger_frames(bindings)
  bindings = bindings.drop(1) if pry_method_frame?(bindings.first)

  # Use the binding returned by #of_caller if possible (as we get
  # access to frame_type).
  # Otherwise stick to the given binding (target).
  if !PryStackExplorer.bindings_equal?(target, bindings.first)
    bindings.shift
    bindings.unshift(target)
  end

  bindings
end