Sha256: 65f63635a16769cad8dcf00624f887696615979e8a9ae6c7ac7856adc7ea9413

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module PryStackExplorer
  class WhenStartedHook

    def caller_bindings(target)
      if binding.of_caller(8).eval('__method__') == :pry
        drop_number = 9
      else
        drop_number = 8
      end

      bindings = binding.callers.drop(drop_number)

      # 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

    def call(target, options, _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 bindings.empty? || !bindings.all? { |v| v.is_a?(Binding) }
          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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pry-stack_explorer-0.3.1 lib/pry-stack_explorer/when_started_hook.rb
pry-stack_explorer-0.3.0 lib/pry-stack_explorer/when_started_hook.rb
pry-stack_explorer-0.2.9pre7 lib/pry-stack_explorer/when_started_hook.rb