Class: MindControl::REPL
- Inherits:
-
Object
- Object
- MindControl::REPL
- Defined in:
- lib/mind_control/repl.rb
Overview
Pry based REPL.
Defined Under Namespace
Classes: CoollineAdapter
Instance Method Summary collapse
-
#initialize(target, options = {}) ⇒ REPL
constructor
A new instance of REPL.
-
#start(stdin, stdout) ⇒ Object
Start REPL session.
Constructor Details
#initialize(target, options = {}) ⇒ REPL
Returns a new instance of REPL.
16 17 18 19 |
# File 'lib/mind_control/repl.rb', line 16 def initialize( target, = {} ) @target = target = end |
Instance Method Details
#start(stdin, stdout) ⇒ Object
Start REPL session.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mind_control/repl.rb', line 27 def start( stdin, stdout ) # NB: We cannot use Readline, because it always uses STDOUT / STDIN. input = CoollineAdapter.new( stdin, stdout ) # Default command set commands = [ :commands ] || ::Pry::CommandSet.new.import( ::Pry::Commands ) # Import our MindControl commands commands.import MindControl::PryCommands # Target can be callable target = @target.respond_to?( :call ) ? @target.call : @target # NB: input/input can't be changed via pry options! pry = ::Pry.new .merge( :commands => commands, :input => input, :output => stdout ) # Store pry instance in thread-local context so that we can later determine # whether we are running inside MindControl session or not. ::Pry.current[ :mind_control_pry_instance ] = pry # Start session pry.repl target end |