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)


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

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



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

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

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



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

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)



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

def self.socket(port)
  "drbunix://#{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)



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

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

Instance Method Details

#pingObject

Returns true



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

def ping
  true
end

#socketObject

The address of the socket for this Server

Returns String (drb address)



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

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

#socket_fileObject

The location of the socket for this Server

Returns String (file location)



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

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

#stopObject

Stop the DRb server and delete the socket file

Returns nothing



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

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