class NebulousStomp::Msg::Header
A class to encapsulate a Nebulous message header - a helper class for Message
Attributes
content_type[R]
The content type of the message
in_reply_to[R]
From The Nebulous Protocol
reply_id[RW]
Might be nil: parsed from incoming messages; set by StompHandler
on send
reply_to[R]
From The Nebulous Protocol
stomp_headers[R]
Might be nil: only caught on messages that came directly from STOMP
Public Class Methods
new(hash)
click to toggle source
# 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
Public Instance Methods
content_is_json?()
click to toggle source
true if the content type appears to be JSON-y
# File lib/nebulous_stomp/msg/header.rb, line 46 def content_is_json? @content_type =~ /json$/i ? true : false end
headers_for_stomp()
click to toggle source
Return the hash of additional headers for the Stomp gem
# 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()
click to toggle source
Output a the header part of the hash for serialization to the cache.
# 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
Private Instance Methods
fill_from_stomp()
click to toggle source
Fill all the other attributes, if you can, from @stomp_headers
# File lib/nebulous_stomp/msg/header.rb, line 78 def fill_from_stomp return unless @stomp_headers type = @stomp_headers["content-type"] || @stomp_headers[:'content-type'] \ || @stomp_headers["content_type"] || @stomp_headers[:content_type] \ || @stomp_headers["contentType"] || @stomp_headers[:contentType] @content_type ||= type @reply_id ||= @stomp_headers['neb-reply-id'] @reply_to ||= @stomp_headers['neb-reply-to'] @in_reply_to ||= @stomp_headers['neb-in-reply-to'] self end