Class: ReplRunner
- Inherits:
-
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.2"
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
#command ⇒ Object
Returns the value of attribute command.
9
10
11
|
# File 'lib/repl_runner.rb', line 9
def command
@command
end
|
#repl ⇒ Object
Returns the value of attribute repl.
9
10
11
|
# File 'lib/repl_runner.rb', line 9
def repl
@repl
end
|
Class Method Details
.known_configs ⇒ Object
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
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
#close ⇒ Object
58
59
60
|
# File 'lib/repl_runner.rb', line 58
def close
repl.close
end
|
#known_configs ⇒ Object
35
36
37
|
# File 'lib/repl_runner.rb', line 35
def known_configs
self.class.known_configs
end
|
#run(&block) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/repl_runner.rb', line 73
def run(&block)
repl = start
yield repl
repl.execute
ensure
close if repl
end
|
#start ⇒ Object
54
55
56
|
# File 'lib/repl_runner.rb', line 54
def start
@repl = MultiRepl.new(command, @config.to_options.merge(@options))
end
|
#zip(string) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/repl_runner.rb', line 62
def zip(string)
results = []
lines = string.lines.map(&:rstrip)
self.run do |repl|
lines.each do |line|
repl.run(line) {|result| results << result }
end
end
lines.zip(results)
end
|