Class: ASIR::Client::Proxy
- Inherits:
-
Object
- Object
- ASIR::Client::Proxy
- Defined in:
- lib/asir/client.rb
Overview
!SLIDE Client Proxy
Provide client interface proxy to a service.
Instance Attribute Summary collapse
-
#__configure ⇒ Object
A Proc to call with the Message object before sending to transport#send_message(message).
-
#_one_way ⇒ Object
If true, this Message is one-way, even if the Transport is bi-directional.
-
#before_send_message ⇒ Object
A Proc to call with the Message object before sending to transport#send_message(message).
-
#receiver ⇒ Object
Returns the value of attribute receiver.
-
#receiver_class ⇒ Object
Returns the value of attribute receiver_class.
-
#transport ⇒ Object
!SLIDE Client Transport.
Class Method Summary collapse
Instance Method Summary collapse
-
#_configure(&blk) ⇒ Object
(also: #_options)
Returns a new Client Proxy with a block to be called with the Message.
- #_configure! ⇒ Object
-
#initialize(rcvr, rcvr_class) ⇒ Proxy
constructor
!SLIDE Configuration Callbacks.
-
#send(selector, *arguments, &block) ⇒ Object
(also: #method_missing)
Accept messages as a proxy for the receiver.
Constructor Details
#initialize(rcvr, rcvr_class) ⇒ Proxy
!SLIDE Configuration Callbacks
102 103 104 105 106 |
# File 'lib/asir/client.rb', line 102 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_missing ⇒ Object
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.
61 62 63 64 65 66 67 |
# File 'lib/asir/client.rb', line 61 def send selector, *arguments, &block = Message.new(@receiver, selector, arguments, block, self) = @before_send_message.call() if @before_send_message @__configure.call(, self) if @__configure result = transport.() result end |
Instance Attribute Details
#__configure ⇒ Object
A Proc to call with the Message object before sending to transport#send_message(message). See #_configure.
83 84 85 |
# File 'lib/asir/client.rb', line 83 def __configure @__configure end |
#_one_way ⇒ Object
If true, this Message is one-way, even if the Transport is bi-directional.
79 80 81 |
# File 'lib/asir/client.rb', line 79 def _one_way @_one_way end |
#before_send_message ⇒ Object
A Proc to call with the Message object before sending to transport#send_message(message). Must return a Message object.
76 77 78 |
# File 'lib/asir/client.rb', line 76 def @before_send_message end |
#receiver ⇒ Object
Returns the value of attribute receiver.
49 50 51 |
# File 'lib/asir/client.rb', line 49 def receiver @receiver end |
#receiver_class ⇒ Object
Returns the value of attribute receiver_class.
49 50 51 |
# File 'lib/asir/client.rb', line 49 def receiver_class @receiver_class end |
#transport ⇒ Object
!SLIDE Client Transport
65 66 67 |
# File 'lib/asir/client.rb', line 65 def transport @transport end |
Class Method Details
.config_callbacks ⇒ Object
118 119 120 |
# File 'lib/asir/client.rb', line 118 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).
92 93 94 95 96 |
# File 'lib/asir/client.rb', line 92 def _configure &blk proxy = @receiver == @receiver_class ? self.dup : self proxy.__configure = blk proxy end |
#_configure! ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/asir/client.rb', line 108 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 59 |
# File 'lib/asir/client.rb', line 53 def send selector, *arguments, &block = Message.new(@receiver, selector, arguments, block, self) = @before_send_message.call() if @before_send_message @__configure.call(, self) if @__configure result = transport.() result end |