Class: Zack::Client

Inherits:
Object
  • Object
show all
Includes:
TransparentProxy
Defined in:
lib/zack/client.rb

Overview

Client for a simple client-server RPC connection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TransparentProxy

#method_missing

Constructor Details

#initialize(tube_name, opts = {}) ⇒ Client

Constructs a client for the service given by tube_name. Optional arguments are:

:server

beanstalkd server location url

:only

ignores all messages not in this hash

:with_answer

these messages wait for an answer from the service



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/zack/client.rb', line 16

def initialize(tube_name, opts={})
  server = opts[:server] || 'beanstalk:11300'
  # Only respond to these messages
  @only        = opts[:only] || proc { true }
  # These have answers (wait for the server to answer)
  @with_answer = opts[:with_answer] || []

  @outgoing = Cod.beanstalk(server, tube_name)
  unless @with_answer.empty?
    @incoming = Cod.beanstalk(server, 
      UniqueName.new(tube_name))
  end

  @service = Cod::Client.new(@outgoing, @incoming, 1)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zack::TransparentProxy

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



7
8
9
# File 'lib/zack/client.rb', line 7

def service
  @service
end

Instance Method Details

#has_answer?(sym) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/zack/client.rb', line 36

def has_answer?(sym)
  @with_answer.include?(sym.to_sym)
end

#respond_to?(msg) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/zack/client.rb', line 32

def respond_to?(msg)
  !! @only[msg]
end