Sha256: a8b23652d5e148b2c5b9bb4b0667334a7b2e85ec80e6c318ef481ed1764295fe

Contents?: true

Size: 1.41 KB

Versions: 10

Compression:

Stored size: 1.41 KB

Contents

class Pry::Testable::PryTester
  extend Pry::Forwardable
  attr_reader :pry, :out
  def_delegators :@pry, :eval_string, :eval_string=

  def initialize(target = TOPLEVEL_BINDING, options = {})
    @pry = Pry.new(options.merge(:target => target))
    @history = options[:history]
    @pry.inject_sticky_locals!
    reset_output
  end

  def eval(*strs)
    reset_output
    result = nil

    strs.flatten.each do |str|
      # Check for space prefix. See #1369.
      if str !~ /^\s\S/
        str = "#{str.strip}\n"
      end
      @history.push str if @history

      if @pry.process_command(str)
        result = last_command_result_or_output
      else
        result = @pry.evaluate_ruby(str)
      end
    end

    result
  end

  def push(*lines)
    Array(lines).flatten.each do |line|
      @pry.eval(line)
    end
  end

  def push_binding(context)
    @pry.push_binding context
  end

  def last_output
    @out.string if @out
  end

  def process_command(command_str)
    @pry.process_command(command_str) or raise "Not a valid command"
    last_command_result_or_output
  end

  def last_command_result
    result = Pry.current[:pry_cmd_result]
    result.retval if result
  end

  protected

  def last_command_result_or_output
    result = last_command_result
    if result != Pry::Command::VOID_VALUE
      result
    else
      last_output
    end
  end

  def reset_output
    @out = StringIO.new
    @pry.output = @out
  end
end

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
xaiml-0.1.3 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
xaiml-0.1.2 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
xaiml-0.1.1 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
xaiml-0.1.0 vendor/bundle/ruby/2.5.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
monero_wallet_gen-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
sb_prime_table-0.1.1 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
sb_prime_table-0.1.0 vendor/bundle/ruby/2.4.0/gems/pry-0.11.3/lib/pry/testable/pry_tester.rb
pry-0.11.3 lib/pry/testable/pry_tester.rb
pry-0.11.3-java lib/pry/testable/pry_tester.rb