Sha256: 12f8ef5d32167686e53ffe15b04b145434084e65e331cfb3d306872b8af0c5ac
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
class Knjappserver def initialize_cmdline @cmds = {} Thread.new do begin line = $stdin.gets next if line == "\n" called = 0 @cmds.each do |key, connects| data = {} if key.is_a?(Regexp) if line.match(key) connects.each do |conn| called += 1 conn[:block].call(data) end end else raise "Unknown class for 'cmd_connect': '#{key.class.name}'." end end if called == 0 print "Unknown command: '#{line.strip}'.\n" end rescue => e self.handle_error(e) end end self.cmd_connect(/^\s*restart\s*$/i) do |data| print "Restart will begin shortly.\n" self.should_restart = true end self.cmd_connect(/^\s*stop\s*$/i) do |data| print "Stopping appserver.\n" self.stop end end #Connects a proc to a specific command in the command-line (key should be a regex). def cmd_connect(cmd, &block) @cmds[cmd] = [] if !@cmds.key?(cmd) @cmds[cmd] << {:block => block} end end
Version data entries
7 entries across 7 versions & 1 rubygems