Class: NebulousStomp::Msg::Header
- Inherits:
-
Object
- Object
- NebulousStomp::Msg::Header
- Defined in:
- lib/nebulous_stomp/msg/header.rb
Overview
A class to encapsulate a Nebulous message header - a helper class for Message
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
The content type of the message.
-
#in_reply_to ⇒ Object
readonly
From The Nebulous Protocol.
-
#reply_id ⇒ Object
Might be nil: parsed from incoming messages; set by StompHandler on send.
-
#reply_to ⇒ Object
readonly
From The Nebulous Protocol.
-
#stomp_headers ⇒ Object
readonly
Might be nil: only caught on messages that came directly from STOMP.
Instance Method Summary collapse
-
#content_is_json? ⇒ Boolean
true if the content type appears to be JSON-y.
-
#headers_for_stomp ⇒ Object
Return the hash of additional headers for the Stomp gem.
-
#initialize(hash) ⇒ Header
constructor
A new instance of Header.
-
#to_h ⇒ Object
Output a the header part of the hash for serialization to the cache.
Constructor Details
#initialize(hash) ⇒ Header
Returns a new instance of Header.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/nebulous_stomp/msg/header.rb', line 29 def initialize(hash) @stomp_headers = hash[:stompHeaders] @reply_to = hash[:replyTo] @reply_id = hash[:replyId] @in_reply_to = hash[:inReplyTo] @content_type = hash[:contentType] # If we have no stomp headers then we (probably correctly) assume that this is a user # created message, and default the content type to JSON. @content_type = 'application/json' if @stomp_headers.nil? && @content_type.nil? fill_from_stomp end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
The content type of the message
22 23 24 |
# File 'lib/nebulous_stomp/msg/header.rb', line 22 def content_type @content_type end |
#in_reply_to ⇒ Object (readonly)
From The Nebulous Protocol
25 26 27 |
# File 'lib/nebulous_stomp/msg/header.rb', line 25 def in_reply_to @in_reply_to end |
#reply_id ⇒ Object
Might be nil: parsed from incoming messages; set by StompHandler on send
16 17 18 |
# File 'lib/nebulous_stomp/msg/header.rb', line 16 def reply_id @reply_id end |
#reply_to ⇒ Object (readonly)
From The Nebulous Protocol
25 26 27 |
# File 'lib/nebulous_stomp/msg/header.rb', line 25 def reply_to @reply_to end |
#stomp_headers ⇒ Object (readonly)
Might be nil: only caught on messages that came directly from STOMP
19 20 21 |
# File 'lib/nebulous_stomp/msg/header.rb', line 19 def stomp_headers @stomp_headers end |
Instance Method Details
#content_is_json? ⇒ Boolean
true if the content type appears to be JSON-y
46 47 48 |
# File 'lib/nebulous_stomp/msg/header.rb', line 46 def content_is_json? @content_type =~ /json$/i ? true : false end |
#headers_for_stomp ⇒ Object
Return the hash of additional headers for the Stomp gem
65 66 67 68 69 70 71 |
# File 'lib/nebulous_stomp/msg/header.rb', line 65 def headers_for_stomp { "content-type" => @content_type, "neb-reply-id" => @reply_id, "neb-reply-to" => @reply_to, "neb-in-reply-to" => @in_reply_to } end |
#to_h ⇒ Object
Output a the header part of the hash for serialization to the cache.
53 54 55 56 57 58 59 60 |
# File 'lib/nebulous_stomp/msg/header.rb', line 53 def to_h { stompHeaders: @stomp_headers, replyTo: @reply_to, replyId: @reply_id, inReplyTo: @in_reply_to, contentType: @content_type } end |