Sha256: 608f4336bfcf95749b51d45020b133a254c2f5a27dde610ea40aed41372e3948

Contents?: true

Size: 1.06 KB

Versions: 25

Compression:

Stored size: 1.06 KB

Contents

Pry::Commands.create_command "yes" do
  description 'Re-runs previous command with "Did you mean?" suggestion.'
  def options(opt)
    opt.on :d, :debug, 'Debug mode.'
  end

  def process
    ex = target.eval("defined?(_ex_) and _ex_")
    return unless ex && ex.message.include?("Did you mean?")

    matched_exception = ex.message.match(
      /undefined.*`(.*)'|uninitialized constant (.*)\n/)
    return unless matched_exception

    typo = matched_exception.captures.compact.first
    return unless typo

    typo_guess = ex.message.split('Did you mean?  ').last.split.first
    last_command = Pry.history.to_a[-2]
    guessed_command = last_command.gsub(typo, typo_guess)

    pry_instance.input = StringIO.new(guessed_command)
  rescue => e
    # Schhh
    raise e if opts.present?(:debug)
  ensure
    if opts.present?(:debug)
      puts "matched_exception: #{matched_exception}"
      puts "typo: #{typo}"
      puts "typo_guess: #{typo_guess}"
      puts "last_command: #{last_command}"
      puts "guessed_command: #{guessed_command}"
    end
  end
end

module PryYes; end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pryx-0.11.0 lib/pry-yes.rb
pryx-0.10.3 lib/pry-yes.rb
pryx-0.10.2 lib/pry-yes.rb
pryx-0.10.1 lib/pry-yes.rb
pryx-0.10.0 lib/pry-yes.rb
pryx-0.9.2 lib/pry-yes.rb
pryx-0.9.0 lib/pry-yes.rb
pryx-0.8.7 lib/pry-yes.rb
pryx-0.8.6 lib/pry-yes.rb
pryx-0.8.5 lib/pry-yes.rb
pryx-0.8.4 lib/pry-yes.rb
pryx-0.8.3 lib/pry-yes.rb
pryx-0.8.2 lib/pry-yes.rb
pryx-0.8.1 lib/pry-yes.rb
pryx-0.8.0 lib/pry-yes.rb
pryx-0.7.2 lib/pry-yes.rb
pryx-0.7.0 lib/pry-yes.rb
pryx-0.6.1 lib/pry-yes.rb
pryx-0.6.0 lib/pry-yes.rb
pryx-0.5.0 lib/pry-yes.rb