Class: NebulousStomp::Msg::Header

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_typeObject (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_toObject (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_idObject

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_toObject (readonly)

From The Nebulous Protocol



25
26
27
# File 'lib/nebulous_stomp/msg/header.rb', line 25

def reply_to
  @reply_to
end

#stomp_headersObject (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

Returns:

  • (Boolean)


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_stompObject

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_hObject

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