Class: StompOut::Frame
- Inherits:
-
Object
- Object
- StompOut::Frame
- Defined in:
- lib/stomp_out/frame.rb
Overview
Container for STOMP frame
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#command ⇒ Object
Returns the value of attribute command.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#initialize(command = nil, headers = nil, body = nil) ⇒ Frame
constructor
Create Stomp frame.
-
#require(version, required) ⇒ Array, Object
Verify that required headers are present and then return their values.
-
#to_s ⇒ String
Serialize frame for transmission on wire.
Constructor Details
#initialize(command = nil, headers = nil, body = nil) ⇒ Frame
Create Stomp frame
34 35 36 37 38 |
# File 'lib/stomp_out/frame.rb', line 34 def initialize(command = nil, headers = nil, body = nil) @command = command @headers = headers || {} @body = body || "" end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
27 28 29 |
# File 'lib/stomp_out/frame.rb', line 27 def body @body end |
#command ⇒ Object
Returns the value of attribute command.
27 28 29 |
# File 'lib/stomp_out/frame.rb', line 27 def command @command end |
#headers ⇒ Object
Returns the value of attribute headers.
27 28 29 |
# File 'lib/stomp_out/frame.rb', line 27 def headers @headers end |
Instance Method Details
#require(version, required) ⇒ Array, Object
Verify that required headers are present and then return their values
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/stomp_out/frame.rb', line 58 def require(version, required) values = [] required.keys.sort.each do |header| exclude = required[header] value = @headers[header] raise ProtocolError.new("Missing '#{header}' header", self) if value.nil? && !exclude.include?(version) values << value end values.size > 1 ? values : values.first end |
#to_s ⇒ String
Serialize frame for transmission on wire
43 44 45 46 |
# File 'lib/stomp_out/frame.rb', line 43 def to_s @headers["content-length"] = @body.size.to_s if @body.include?(NULL) @headers.keys.sort.inject("#{@command}\n") { |r, key| r << "#{key}:#{@headers[key]}\n" } + "\n#{@body}#{NULL}\n" end |