Class: Stomper::Scopes::HeaderScope
- Inherits:
-
Object
- Object
- Stomper::Scopes::HeaderScope
- 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
Constant Summary
Constants included from Extensions::Common
Extensions::Common::EXTEND_BY_VERSION
Instance Attribute Summary collapse
-
#connection ⇒ Stomper::Connection
readonly
The underlying connection to transmit frames through.
-
#headers ⇒ {Symbol => String}
readonly
The headers to apply to all frames generated on this scope.
Instance Method Summary collapse
-
#apply_to(callback) ⇒ Object
Applies this scope to a block.
-
#initialize(connection, headers) ⇒ HeaderScope
constructor
Creates a new HeaderScope.
-
#receipt_manager ⇒ Stomper::ReceiptManager
Returns the connection’s ReceiptManager.
-
#subscription_manager ⇒ Stomper::SubscriptionManager
Returns the connection’s Stomper::SubscriptionManager.
-
#transmit(frame) ⇒ Object
Transmits a frame, applying the set headers.
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.)
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
#connection ⇒ Stomper::Connection (readonly)
The underlying connection to transmit frames through.
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.
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_manager ⇒ Stomper::ReceiptManager
Returns the connection’s ReceiptManager
44 |
# File 'lib/stomper/scopes/header_scope.rb', line 44 def receipt_manager; @connection.receipt_manager; end |
#subscription_manager ⇒ Stomper::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.
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 |