class Pry::CommandProcessor

def check_for_command_name_collision(command_name_match, target)

Parameters:
  • target (Binding) -- The current binding context.
  • command_name_match (String) -- The name of the colliding command.
def check_for_command_name_collision(command_name_match, target)
  if collision_type = target.eval("defined?(#{command_name_match})")
    pry_instance.output.puts "#{Pry::Helpers::Text.bold('WARNING:')} Command name collision with a #{collision_type}: '#{command_name_match}'\n\n"
  end
rescue Pry::RescuableException
end

def command_matched(val, target)

Returns:
  • (Array) - The command data and arg string pair

Parameters:
  • target (Binding) -- The binding to perform string
  • val (String) -- The line of input.
def command_matched(val, target)
  _, cmd_data = commands.commands.find do |name, data|
    prefix = convert_to_regex(Pry.config.command_prefix)
    prefix = "(?:#{prefix})?" unless data.options[:use_prefix]
    command_regex = /^#{prefix}#{convert_to_regex(name)}(?!\S)/
    if command_regex =~ val
      if data.options[:interpolate]
        val.replace(interpolate_string(val, target))
        command_regex =~ val # re-match with the interpolated string
      end
      true
    end
  end
  [cmd_data, (Regexp.last_match ? Regexp.last_match.captures : nil), (Regexp.last_match ? Regexp.last_match.end(0) : nil)]
end

def convert_to_regex(obj)

Returns:
  • (String) - The string to interpolate into a Regexp
def convert_to_regex(obj)
  case obj
  when String
    Regexp.escape(obj)
  else
    obj
  end
end

def execute_command(target, command, options, *args)

Returns:
  • (Object) - The value returned by the command

Parameters:
  • args (Array) -- The command arguments.
  • options (Hash) -- The options to set on the Commands object.
  • command (String) -- The name of the command to be run.
  • target (Binding) -- The target of the Pry session.
def execute_command(target, command, options, *args)
  context = CommandContext.new
  # set some useful methods to be used by the action blocks
  context.opts        = options
  context.target      = target
  context.target_self = target.eval('self')
  context.output      = output
  context.captures    = options[:captures]
  context.eval_string = options[:eval_string]
  context.arg_string  = options[:arg_string]
  context.command_set = commands
  context._pry_ = @pry_instance
  context.command_processor = self
  ret = nil
  catch(:command_done) do
    ret = commands.run_command(context, command, *args)
  end
  options[:val].replace("")
  ret
end

def initialize(pry_instance)

def initialize(pry_instance)
  @pry_instance = pry_instance
end

def interpolate_string(str, target)

Returns:
  • (String) - The reevaluated string with interpolations

Parameters:
  • target (Binding) -- The context where the string should be
  • str (String) -- The string to reevaluate with interpolation.
def interpolate_string(str, target)
  dumped_str = str.dump
  dumped_str.gsub!(/\\\#\{/, '#{')
  target.eval(dumped_str)
end

def process_commands(val, eval_string, target)

Returns:
  • (Pry::CommandProcessor::Result) - A wrapper object

Parameters:
  • target (Binding) -- The receiver of the commands.
  • eval_string (String) -- The cumulative lines of input for
  • val (String) -- The current line of input.
def process_commands(val, eval_string, target)
  command, captures, pos = command_matched(val, target)
  # no command was matched, so return to caller
  return Result.new(false) if !command
  arg_string = val[pos..-1]
  check_for_command_name_collision(val[0..pos].rstrip, target) if Pry.config.collision_warning
  # remove the one leading space if it exists
  arg_string.slice!(0) if arg_string.start_with?(" ")
  if arg_string
    args = command.options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ")
  else
    args = []
  end
  options = {
    :val => val,
    :arg_string => arg_string,
    :eval_string => eval_string,
    :commands => commands.commands,
    :captures => captures
  }
  ret = execute_command(target, command.name, options, *(captures + args))
  Result.new(true, command.options[:keep_retval], ret)
end

def valid_command?(val, target=binding)

Returns:
  • (Boolean) - Whether the string is a valid command.

Parameters:
  • target (Binding) -- The context where the string should be
  • val (String) -- The string passed in from the Pry prompt.
def valid_command?(val, target=binding)
  !!(command_matched(val, target)[0])
end