lib/lotus/commands/console.rb in lotusrb-0.5.0 vs lib/lotus/commands/console.rb in lotusrb-0.6.0

- old
+ new

@@ -1,7 +1,15 @@ module Lotus module Commands + # REPL that supports different engines. + # + # It is run with: + # + # `bundle exec lotus console` + # + # @since 0.1.0 + # @api private class Console module Methods def reload! puts 'Reloading...' Kernel.exec "#{$0} console" @@ -12,17 +20,25 @@ 'pry' => 'Pry', 'ripl' => 'Ripl', 'irb' => 'IRB' }.freeze + DEFAULT_ENGINE = 'irb'.freeze + + # @since 0.1.0 attr_reader :options - def initialize(environment) - @environment = environment - @options = environment.to_options + # @param options [Hash] Environment's options + # + # @since 0.1.0 + # @see Lotus::Environment#initialize + def initialize(options) + @environment = Lotus::Environment.new(options) + @options = @environment.to_options end + # @since 0.1.0 def start # Clear out ARGV so Pry/IRB don't attempt to parse the rest ARGV.shift until ARGV.empty? @environment.require_application_environment @@ -31,24 +47,26 @@ load_application engine.start end + # @since 0.1.0 + # @api private def engine load_engine options.fetch(:engine) { engine_lookup } end private + # @since 0.1.0 + # @api private def engine_lookup - (ENGINES.find { |_, klass| Object.const_defined?(klass) } || default_engine).first + (ENGINES.find { |_, klass| Object.const_defined?(klass) } || DEFAULT_ENGINE).first end - def default_engine - ENGINES.to_a.last - end - + # @since 0.1.0 + # @api private def load_engine(engine) require engine rescue LoadError ensure return Object.const_get( @@ -56,9 +74,11 @@ raise ArgumentError.new("Unknown console engine: #{ engine }") } ) end + # @since 0.1.0 + # @api private def load_application if @environment.container? Lotus::Container.new else Lotus::Application.preload_applications!