Class: Boogaloo::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/boogaloo/client/connection.rb

Overview

A wrapper around DRb for connecting to the boogaloo server.

Example usage:

boogaloo_cache = Boogaloo::Client::Connection.new('localhost', 7777, true)

Instance Method Summary collapse

Constructor Details

#initialize(host, port, wrap = false) ⇒ Connection

Create a new connection to the boogaloo server.

Parameters:

host

The host name or IP address to bind the socket to.

port

The port to bind the socket to.

wrap

If true, attempts to access the server when it is offline will result in a nil being returned instead of an exception being raised.



19
20
21
22
23
24
25
26
# File 'lib/boogaloo/client/connection.rb', line 19

def initialize(host, port, wrap=false)

    @wrap = wrap
    druby_str = "druby://#{host}:#{port}"
    DRb.start_service
    @conn = DRbObject.new(nil, druby_str)
    
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(msg_id, *a, &b) ⇒ Object

Forwards all method calls to the server.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/boogaloo/client/connection.rb', line 29

def method_missing(msg_id, *a, &b)
            
    if @wrap
    
        begin
        
            return @conn.method_missing(msg_id, a, b)
        
        rescue DRb::DRbConnError
        
            return nil
        
        end
    
    else
    
        return @conn.method_missing(msg_id, a, b)
        
    end

end