Sha256: ade378897682c0bb04c6e275a80303f0495dc7131dfb6b380a05941a667d4064
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
# frozen_string_literal: true require 'xip/commands/command' module Xip module Commands # REPL that supports different engines. # # It is run with: # # `bundle exec xip console` class Console < Command module CodeReloading def reload! puts 'Reloading...' Kernel.exec "#{$PROGRAM_NAME} console" end end # Supported engines ENGINES = { 'pry' => 'Pry', 'ripl' => 'Ripl', 'irb' => 'IRB' }.freeze DEFAULT_ENGINE = ['irb'].freeze attr_reader :options def initialize(options) super(options) @options = options end def start prepare engine.start end def engine load_engine options.fetch(:engine) { engine_lookup } end private def prepare # Clear out ARGV so Pry/IRB don't attempt to parse the rest ARGV.shift until ARGV.empty? # Add convenience methods to the main:Object binding TOPLEVEL_BINDING.eval('self').__send__(:include, CodeReloading) Xip.boot end def engine_lookup (ENGINES.find { |_, klass| Object.const_defined?(klass) } || DEFAULT_ENGINE).first end def load_engine(engine) require engine rescue LoadError ensure return Object.const_get( ENGINES.fetch(engine) do raise ArgumentError.new("Unknown console engine: `#{engine}'") end ) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
xip-2.0.0.beta2 | lib/xip/commands/console.rb |