Class: ReplRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/repl_runner.rb,
lib/repl_runner/config.rb,
lib/repl_runner/version.rb,
lib/repl_runner/pty_party.rb,
lib/repl_runner/multi_repl.rb,
lib/repl_runner/multi_command_parser.rb

Defined Under Namespace

Classes: Config, MultiCommandParser, MultiRepl, NoResults, PtyParty, UnregisteredCommand

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd_type, command = nil, options = {}) ⇒ ReplRunner

Returns a new instance of ReplRunner.



25
26
27
28
29
30
31
32
33
# File 'lib/repl_runner.rb', line 25

def initialize(cmd_type, command = nil, options = {})
  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  = known_configs[cmd_type]
  raise UnregisteredCommand.new(cmd_type) unless @config
  @options = options
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



9
10
11
# File 'lib/repl_runner.rb', line 9

def command
  @command
end

#replObject

Returns the value of attribute repl.



9
10
11
# File 'lib/repl_runner.rb', line 9

def repl
  @repl
end

Class Method Details

.known_configsObject



40
41
42
# File 'lib/repl_runner.rb', line 40

def known_configs
  @known_configs ||= {}
end

.register_command(*commands) {|config| ... } ⇒ Object Also known as: register_commands

Yields:

  • (config)


44
45
46
47
48
49
50
# File 'lib/repl_runner.rb', line 44

def register_command(*commands, &block)
  config = Config.new(commands)
  commands.each do |command|
    known_configs[command] = config
  end
  yield config
end

Instance Method Details

#closeObject



58
59
60
# File 'lib/repl_runner.rb', line 58

def close
  repl.close
end

#known_configsObject



35
36
37
# File 'lib/repl_runner.rb', line 35

def known_configs
  self.class.known_configs
end

#run(&block) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/repl_runner.rb', line 62

def run(&block)
  repl = start
  yield repl
  repl.execute
ensure
  close if repl
end

#startObject



54
55
56
# File 'lib/repl_runner.rb', line 54

def start
  @repl = MultiRepl.new(command, @config.to_options.merge(@options))
end