Class: Stomper::Scopes::HeaderScope

Inherits:
Object
  • Object
show all
Includes:
Extensions::Common
Defined in:
lib/stomper/scopes/header_scope.rb

Overview

A “connection scope” that provides much of the same interface as Connection, but automatically applies header name/value pairs to all frames generated on the scope.

Direct Known Subclasses

ReceiptScope, TransactionScope

Constant Summary

Constants included from Extensions::Common

Extensions::Common::EXTEND_BY_VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Extensions::Common

#abort, #ack, #begin, #commit, #disconnect, extend_by_protocol_version, #nack, #send, #subscribe, #unsubscribe

Constructor Details

#initialize(connection, headers) ⇒ HeaderScope

Creates a new Stomper::Scopes::HeaderScope. The supplied headers hash will have all of its keys converted to symbols and its values converted to strings, so the key/value pairs must support this transformation (through to_sym and to_s, respectively.)

Parameters:



22
23
24
25
26
# File 'lib/stomper/scopes/header_scope.rb', line 22

def initialize(connection, headers)
  @headers = ::Stomper::Support.keys_to_sym(headers)
  @connection = connection
  ::Stomper::Extensions::Common.extend_by_protocol_version(self, @connection.version)
end

Instance Attribute Details

#connectionStomper::Connection (readonly)

The underlying connection to transmit frames through.

Returns:



11
12
13
# File 'lib/stomper/scopes/header_scope.rb', line 11

def connection
  @connection
end

#headers{Symbol => String} (readonly)

The headers to apply to all frames generated on this scope.

Returns:

  • ({Symbol => String})


14
15
16
# File 'lib/stomper/scopes/header_scope.rb', line 14

def headers
  @headers
end

Instance Method Details

#apply_to(callback) ⇒ Object

Applies this scope to a block.



29
30
31
# File 'lib/stomper/scopes/header_scope.rb', line 29

def apply_to(callback)
  callback.call(self) if callback
end

#receipt_managerStomper::ReceiptManager

Returns the connection’s ReceiptManager



44
# File 'lib/stomper/scopes/header_scope.rb', line 44

def receipt_manager; @connection.receipt_manager; end

#subscription_managerStomper::SubscriptionManager

Returns the connection’s Stomper::SubscriptionManager



48
# File 'lib/stomper/scopes/header_scope.rb', line 48

def subscription_manager; @connection.subscription_manager; end

#transmit(frame) ⇒ Object

Transmits a frame, applying the set headers. After merging its headers into the frame, the frame is passed to the underlying connection for transmission.

Parameters:



37
38
39
40
# File 'lib/stomper/scopes/header_scope.rb', line 37

def transmit(frame)
  frame.headers.reverse_merge!(@headers)
  @connection.transmit frame
end