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



5
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
34
# File 'lib/pry-stack_explorer/when_started_hook.rb', line 5

def call(target, options, _pry_)
  start_from_console = target.eval('__callee__').nil? &&
    target.eval('__FILE__') == '<main>' &&
    target.eval('__LINE__') == 0
  return if start_from_console

  options = {
    call_stack: true
  }.merge!(options)

  return unless options[:call_stack]
  initial_frame = options[:initial_frame]

  if options[:call_stack].is_a?(Array)
    bindings = options[:call_stack]
    initial_frame ||= 0
    unless valid_call_stack?(bindings)
      raise ArgumentError, ":call_stack must be an array of bindings"
    end
  else
    bindings = PryMoves::BindingsStack.new options
    initial_frame ||= bindings.suggest_initial_frame_index
    # if Thread.current[:pry_moves_debug] and initial_frame > 0
    if initial_frame > 0
      PryMoves.messages << "👽  Frames hidden: #{initial_frame}"
    end
  end

  PryStackExplorer.create_and_push_frame_manager bindings, _pry_, initial_frame: initial_frame
end