Sha256: 54855beba02c64a95440b6d85ceb2cf289e94adad6b1e784fd639c2c10a12c9f

Contents?: true

Size: 1.23 KB

Versions: 14

Compression:

Stored size: 1.23 KB

Contents

module PryStackExplorer
  class WhenStartedHook
    include Pry::Helpers::BaseHelpers

    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

    private

    def valid_call_stack?(bindings)
      bindings.any? && bindings.all? { |v| v.is_a?(Binding) }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pry-moves-1.0.15 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.14 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.13 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.12 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.11 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.10 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.9 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.8 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.7 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.6 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.5 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.4 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.3 lib/pry-stack_explorer/when_started_hook.rb
pry-moves-1.0.2 lib/pry-stack_explorer/when_started_hook.rb