Class: Codebot::IPCServer

Inherits:
ThreadController show all
Defined in:
lib/codebot/ipc_server.rb

Overview

A pipe-based IPC server used for communicating with a running Codebot instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThreadController

#join, #running?, #start, #start!, #stop!

Constructor Details

#initialize(core, pipe = nil) ⇒ IPCServer

Creates a new IPC server.

Parameters:

  • core (Core)

    the bot this server belongs to

  • pipe (String) (defaults to: nil)

    the path to the named pipe, or nil to use the default pipe for this user



18
19
20
21
22
# File 'lib/codebot/ipc_server.rb', line 18

def initialize(core, pipe = nil)
  super()
  @core = core
  @pipe = pipe || self.class.default_pipe
end

Instance Attribute Details

#coreCore (readonly)

Returns the bot this server belongs to.

Returns:

  • (Core)

    the bot this server belongs to



8
9
10
# File 'lib/codebot/ipc_server.rb', line 8

def core
  @core
end

#pipeString (readonly)

Returns the path to the named pipe.

Returns:

  • (String)

    the path to the named pipe



11
12
13
# File 'lib/codebot/ipc_server.rb', line 11

def pipe
  @pipe
end

Class Method Details

.default_pipeString

Returns the path to the default pipe for the current user.

Returns:

  • (String)

    the path to the named pipe



38
39
40
# File 'lib/codebot/ipc_server.rb', line 38

def self.default_pipe
  File.join Dir.home, '.codebot.ipc'
end

Instance Method Details

#stopThread?

Stops the managed thread if a thread is currently running, then deletes the named pipe.

Returns:

  • (Thread, nil)

    the stopped thread, or nil if no thread was running



29
30
31
32
33
# File 'lib/codebot/ipc_server.rb', line 29

def stop
  thr = super
  delete_pipe
  thr
end