Class: CommandServer
- Inherits:
-
Object
- Object
- CommandServer
- Defined in:
- lib/command_server/version.rb,
lib/command_server/command_server.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
- #enable_builtin_command(name) ⇒ Object
-
#initialize ⇒ CommandServer
constructor
A new instance of CommandServer.
- #register_command(name, proc_obj, description = "") ⇒ Object
- #start(addr) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ CommandServer
Returns a new instance of CommandServer.
5 6 7 |
# File 'lib/command_server/command_server.rb', line 5 def initialize @cmds = {} end |
Instance Method Details
#enable_builtin_command(name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/command_server/command_server.rb', line 36 def enable_builtin_command name proc_name = "builtin_command_#{name}" if self.respond_to?(proc_name, true) register_command name, method(proc_name.to_sym) else raise NameError.new("Undefined builtin command: #{name}") end end |
#register_command(name, proc_obj, description = "") ⇒ Object
32 33 34 |
# File 'lib/command_server/command_server.rb', line 32 def register_command name, proc_obj, description="" @cmds[name] = {proc: proc_obj, desc: description} end |
#start(addr) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/command_server/command_server.rb', line 9 def start addr @addr = addr @server = UNIXServer.new(@addr) $stderr.puts "[CommandServer] Server start: #{@addr}" at_exit do stop end @accept_thread = Thread.new do @accept_thread.abort_on_exception = true loop do accept_and_process end end end |
#stop ⇒ Object
27 28 29 30 |
# File 'lib/command_server/command_server.rb', line 27 def stop File.unlink @addr @accept_thread.exit end |