Class: Pry::CommandProcessor
- Inherits:
-
Object
- Object
- Pry::CommandProcessor
- Extended by:
- Forwardable
- Defined in:
- lib/pry/command_processor.rb
Instance Attribute Summary (collapse)
-
- (Object) pry_instance
Returns the value of attribute pry_instance.
Instance Method Summary (collapse)
-
- (Array) command_matched(val, target)
Determine whether a Pry command was matched and return command data and argument string.
-
- (String) convert_to_regex(obj)
Convert the object to a form that can be interpolated into a Regexp cleanly.
-
- (Object) execute_command(target, command, options, *args)
Execute a Pry command.
-
- (CommandProcessor) initialize(pry_instance)
constructor
A new instance of CommandProcessor.
-
- (String) interpolate_string(str, target)
Revaluate the string (str) and perform interpolation.
-
- (Object) process_commands(val, eval_string, target)
Process Pry commands.
-
- (Boolean) valid_command?(val, target = binding)
Is the string a valid command?.
Constructor Details
- (CommandProcessor) initialize(pry_instance)
A new instance of CommandProcessor
9 10 11 |
# File 'lib/pry/command_processor.rb', line 9 def initialize(pry_instance) @pry_instance = pry_instance end |
Instance Attribute Details
- (Object) pry_instance
Returns the value of attribute pry_instance
7 8 9 |
# File 'lib/pry/command_processor.rb', line 7 def pry_instance @pry_instance end |
Instance Method Details
- (Array) command_matched(val, target)
Determine whether a Pry command was matched and return command data and argument string. This method should not need to be invoked directly.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pry/command_processor.rb', line 55 def command_matched(val, target) _, cmd_data = commands.commands.find do |name, data| command_regex = /^#{convert_to_regex(name)}(?!\S)/ if data.[:interpolate] # If interpolation fails then the command cannot be matched, # so early exit. begin interp_val = interpolate_string(val, target) rescue NameError next end val.replace interp_val if command_regex =~ interp_val else command_regex =~ val end end [cmd_data, (Regexp.last_match ? Regexp.last_match.captures : nil), (Regexp.last_match ? Regexp.last_match.end(0) : nil)] end |
- (String) convert_to_regex(obj)
Convert the object to a form that can be interpolated into a Regexp cleanly.
27 28 29 30 31 32 33 34 |
# File 'lib/pry/command_processor.rb', line 27 def convert_to_regex(obj) case obj when String Regexp.escape(obj) else obj end end |
- (Object) execute_command(target, command, options, *args)
Execute a Pry command. This method should not need to be invoked directly.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/pry/command_processor.rb', line 117 def execute_command(target, command, , *args) context = CommandContext.new # set some useful methods to be used by the action blocks context.opts = context.target = target context.output = output context.captures = [:captures] context.eval_string = [:eval_string] context.arg_string = [:arg_string] context.command_set = commands context.command_processor = self ret = commands.run_command(context, command, *args) # Tick, tock, im getting rid of this shit soon. [:val].replace("") ret end |
- (String) interpolate_string(str, target)
Revaluate the string (str) and perform interpolation.
42 43 44 45 46 |
# File 'lib/pry/command_processor.rb', line 42 def interpolate_string(str, target) dumped_str = str.dump dumped_str.gsub!(/\\\#\{/, '#{') target.eval(dumped_str) end |
- (Object) process_commands(val, eval_string, target)
Process Pry commands. Pry commands are not Ruby methods and are evaluated
prior to Ruby expressions.
Commands can be modified/configured by the user: see Pry::Commands
This method should not need to be invoked directly - it is called
by Pry#r.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/pry/command_processor.rb', line 87 def process_commands(val, eval_string, target) # no command was matched, so return to caller command, captures, pos = command_matched(val, target) return if !command arg_string = val[pos..-1] # remove the one leading space if it exists arg_string.slice!(0) if arg_string.start_with?(" ") args = arg_string ? Shellwords.shellwords(arg_string) : [] = { :val => val, :arg_string => arg_string, :eval_string => eval_string, :nesting => nesting, :commands => commands.commands, :captures => captures } execute_command(target, command.name, , *(captures + args)) end |
- (Boolean) valid_command?(val, target = binding)
Is the string a valid command?
20 21 22 |
# File 'lib/pry/command_processor.rb', line 20 def valid_command?(val, target=binding) !!(command_matched(val, target)[0]) end |