Class: ASIR::Client::Proxy

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

Overview

!SLIDE Client Proxy

Provide client interface proxy to a service.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rcvr, rcvr_class) ⇒ Proxy

!SLIDE Configuration Callbacks



101
102
103
104
105
# File 'lib/asir/client.rb', line 101

def initialize rcvr, rcvr_class
  @receiver = rcvr
  @receiver_class = rcvr_class
  _configure!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

Accept messages as a proxy for the receiver. Blocks are used represent a “continuation” for the Result. Accept all other messages to be encoded and transported to a service.



60
61
62
63
64
65
# File 'lib/asir/client.rb', line 60

def send selector, *arguments, &block
  message = Message.new(@receiver, selector, arguments, block, self)
  message = @before_send_message.call(message) if @before_send_message
  @__configure.call(message, self) if @__configure
  transport.send_message(message) # => result
end

Instance Attribute Details

#__configureObject

A Proc to call with the Message object before sending to transport#send_message(message). See #_configure.



82
83
84
# File 'lib/asir/client.rb', line 82

def __configure
  @__configure
end

#_one_wayObject

If true, this Message is one-way, even if the Transport is bi-directional.



78
79
80
# File 'lib/asir/client.rb', line 78

def _one_way
  @_one_way
end

#before_send_messageObject

A Proc to call with the Message object before sending to transport#send_message(message). Must return a Message object.



75
76
77
# File 'lib/asir/client.rb', line 75

def before_send_message
  @before_send_message
end

#receiverObject

Returns the value of attribute receiver.



49
50
51
# File 'lib/asir/client.rb', line 49

def receiver
  @receiver
end

#receiver_classObject

Returns the value of attribute receiver_class.



49
50
51
# File 'lib/asir/client.rb', line 49

def receiver_class
  @receiver_class
end

#transportObject

!SLIDE Client Transport



64
65
66
# File 'lib/asir/client.rb', line 64

def transport
  @transport
end

Class Method Details

.config_callbacksObject



117
118
119
# File 'lib/asir/client.rb', line 117

def self.config_callbacks
  @@config_callbacks
end

Instance Method Details

#_configure(&blk) ⇒ Object Also known as: _options

Returns a new Client Proxy with a block to be called with the Message. This block can configure additional options of the Message before it is sent to the Transport.

Call sequence:

proxy.__configure.call(message, proxy).


91
92
93
94
95
# File 'lib/asir/client.rb', line 91

def _configure &blk
  proxy = @receiver == @receiver_class ? self.dup : self
  proxy.__configure = blk
  proxy
end

#_configure!Object



107
108
109
110
111
112
113
114
# File 'lib/asir/client.rb', line 107

def _configure!
  key = @receiver_class
  (@@config_callbacks[key] ||
   @@config_callbacks[key.name] ||
   @@config_callbacks[nil] ||
   IDENTITY_LAMBDA).call(self)
  self
end

#send(selector, *arguments, &block) ⇒ Object Also known as: method_missing

Accept messages as a proxy for the receiver. Blocks are used represent a “continuation” for the Result.



53
54
55
56
57
58
# File 'lib/asir/client.rb', line 53

def send selector, *arguments, &block
  message = Message.new(@receiver, selector, arguments, block, self)
  message = @before_send_message.call(message) if @before_send_message
  @__configure.call(message, self) if @__configure
  transport.send_message(message) # => result
end