Module: OnStomp::OpenURI::ClientExtensions
- Defined in:
- lib/onstomp/open-uri/client_extensions.rb
Overview
Mixin of extensions added to clients when they are created by opening a stomp:// URI.
Instance Attribute Summary collapse
-
#auto_destination ⇒ Object
Returns the value of attribute auto_destination.
-
#openuri_message_queue ⇒ Object
readonly
Returns the value of attribute openuri_message_queue.
Class Method Summary collapse
-
.extended(inst) ⇒ Object
Aliases #send_with_openuri as
send
.
Instance Method Summary collapse
-
#each {|m| ... } ⇒ Enumerator, self
Creates a subscription to #auto_destination and yields each MESSAGE frame read from the subscription to the supplied block.
-
#first(n = nil) ⇒ OnStomp::Components::Frame+
(also: #take, #gets)
Returns
n
frames read from the subscription. -
#send_with_openuri(*args, &block) ⇒ OnStomp::Components::Frame
Adds the ability for clients to generate SEND frames without specifying a destination by using #auto_destination instead.
Instance Attribute Details
#auto_destination ⇒ Object
Returns the value of attribute auto_destination.
6 7 8 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 6 def auto_destination @auto_destination end |
#openuri_message_queue ⇒ Object (readonly)
Returns the value of attribute openuri_message_queue.
6 7 8 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 6 def @openuri_message_queue end |
Class Method Details
.extended(inst) ⇒ Object
Aliases #send_with_openuri as send
9 10 11 12 13 14 15 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 9 def self.extended inst inst.instance_eval do alias :send_without_openuri :send alias :send :send_with_openuri alias :puts :send end end |
Instance Method Details
#each {|m| ... } ⇒ Enumerator, self
Creates a subscription to #auto_destination and yields each MESSAGE frame read from the subscription to the supplied block. If no block is provided an enumerator is returned.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 35 def each(&block) if block subscribe_to_auto_destination loop do yield .shift end else OnStomp::ENUMERATOR_KLASS.new(self) end end |
#first(n = nil) ⇒ OnStomp::Components::Frame+ Also known as: take, gets
Returns n
frames read from the subscription. If n
is ommited, the next frame is returned, otherwise an array of the next n
frames is returned.
52 53 54 55 56 57 58 59 60 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 52 def first(n=nil) to_recv = n || 1 received = [] each do |m| received << m break if received.size == to_recv end n ? received : received.first end |
#send_with_openuri(*args, &block) ⇒ OnStomp::Components::Frame
Adds the ability for clients to generate SEND frames without specifying a destination by using #auto_destination instead.
20 21 22 23 24 25 26 27 |
# File 'lib/onstomp/open-uri/client_extensions.rb', line 20 def send_with_openuri *args, &block headers = args.last.is_a?(Hash) ? args.pop : {} dest, body = args if body.nil? body, dest = dest, verified_auto_destination end send_without_openuri dest, body, headers, &block end |