Class: God::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/god/socket.rb

Overview

The God::Server oversees the DRb server which dishes out info on this God daemon.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = nil, user = nil, group = nil, perm = nil) ⇒ Socket

Create a new Server and star the DRb server

+port+ is the port on which to start the DRb service (default nil)


41
42
43
44
45
46
47
# File 'lib/god/socket.rb', line 41

def initialize(port = nil, user = nil, group = nil, perm = nil)
  @port  = port
  @user  = user
  @group = group
  @perm  = perm
  start
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object

Forward API calls to God

Returns whatever the forwarded call returns



57
58
59
# File 'lib/god/socket.rb', line 57

def method_missing(*args, &block)
  God.send(*args, &block)
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/god/socket.rb', line 7

def port
  @port
end

Class Method Details

.socket(port) ⇒ Object

The address of the socket for a given port

+port+ is the port number

Returns String (drb address)



21
22
23
# File 'lib/god/socket.rb', line 21

def self.socket(port)
  "drbunix://#{self.socket_file(port)}"
end

.socket_file(port) ⇒ Object

The location of the socket for a given port

+port+ is the port number

Returns String (file location)



13
14
15
# File 'lib/god/socket.rb', line 13

def self.socket_file(port)
  "/tmp/god.#{port}.sock"
end

Instance Method Details

#pingObject

Returns true



50
51
52
# File 'lib/god/socket.rb', line 50

def ping
  true
end

#socketObject

The address of the socket for this Server

Returns String (drb address)



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

def socket
  self.class.socket(@port)
end

#socket_fileObject

The location of the socket for this Server

Returns String (file location)



28
29
30
# File 'lib/god/socket.rb', line 28

def socket_file
  self.class.socket_file(@port)
end

#stopObject

Stop the DRb server and delete the socket file

Returns nothing



64
65
66
67
# File 'lib/god/socket.rb', line 64

def stop
  DRb.stop_service
  FileUtils.rm_f(self.socket_file)
end