class ReplRunner
Constants
- VERSION
Attributes
command[RW]
config[RW]
repl[RW]
Public Class Methods
known_configs()
click to toggle source
# File lib/repl_runner.rb, line 49 def known_configs @known_configs ||= {} end
new(cmd_type, command = nil, options = {})
click to toggle source
# File lib/repl_runner.rb, line 26 def initialize(cmd_type, command = nil, options = {}) raise "Unexpected block, use the `run` command instead?" if block_given? command = cmd_type.to_s if command.nil? cmd_type = cmd_type.chomp.gsub(/\s/, '_').to_sym if cmd_type.is_a?(String) @command = command @repl = nil @config = get_config_for_command(cmd_type) raise UnregisteredCommand.new(cmd_type) unless @config @options = options end
register_command(*commands) { |config| ... }
click to toggle source
# File lib/repl_runner.rb, line 53 def register_command(*commands, &block) config = Config.new(commands) commands.each do |command| known_configs[command] = config end yield config end
Also aliased as: register_commands
Public Instance Methods
close()
click to toggle source
# File lib/repl_runner.rb, line 67 def close repl.close end
get_config_for_command(cmd_type)
click to toggle source
# File lib/repl_runner.rb, line 37 def get_config_for_command(cmd_type) known_configs.detect do |cmd_match, config| return config if cmd_match == cmd_type return config if cmd_match.is_a?(Regexp) && cmd_match =~ cmd_type.to_s end end
known_configs()
click to toggle source
# File lib/repl_runner.rb, line 44 def known_configs self.class.known_configs end
run() { |repl| ... }
click to toggle source
# File lib/repl_runner.rb, line 82 def run(&block) repl = start yield repl repl.execute ensure close if repl end
start()
click to toggle source
# File lib/repl_runner.rb, line 63 def start @repl = MultiRepl.new(command, @config.to_options.merge(@options)) end
zip(string)
click to toggle source
# File lib/repl_runner.rb, line 71 def zip(string) results = [] inputs = string.lines.map(&:rstrip) self.run do |repl| inputs.each do |line| repl.run(line) {|result| results << result } end end inputs.zip(results) end