Class: Stomper::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/stomper/frame.rb

Overview

A generic encapsulation of a frame as specified by the Stomp protocol.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command = nil, headers = {}, body = nil) ⇒ Frame

Creates a new frame. The frame will be initialized with the optional command name, a headers collection initialized with the optional headers hash, and an optional body.



20
21
22
23
24
# File 'lib/stomper/frame.rb', line 20

def initialize(command=nil, headers={}, body=nil)
  @command = command
  @headers = ::Stomper::Headers.new(headers)
  @body = body
end

Instance Attribute Details

#bodyString

The body of this frame

Returns:

  • (String)

    if a body has been set



11
12
13
# File 'lib/stomper/frame.rb', line 11

def body
  @body
end

#commandString

The command name of this frame (CONNECTED, SEND, RECEIPT, etc.)

Returns:

  • (String)


7
8
9
# File 'lib/stomper/frame.rb', line 7

def command
  @command
end

#headersStomper::Headers (readonly)

The headers associated with this frame

Returns:



15
16
17
# File 'lib/stomper/frame.rb', line 15

def headers
  @headers
end

Instance Method Details

#[](name) ⇒ String

Gets the header value paired with the supplied name. This is a convenient shortcut for ‘frame.headers`.

Examples:

frame['content-type'] #=> 'text/plain'

Parameters:

  • name (Object)

    the header name associated with the desired value

Returns:

  • (String)

    the value associated with the requested header name

See Also:

  • Headers#[]


34
# File 'lib/stomper/frame.rb', line 34

def [](name); @headers[name]; end

#[]=(name, val) ⇒ String

Sets the header value paired with the supplied name. This is a convenient shortcut for ‘frame.headers = val`.

Examples:

frame['content-type'] = 'text/plain' #=> 'text/plain'
frame['other header'] = 42 #=> '42'

Parameters:

  • name (Object)

    the header name to associate with the supplied value

  • val (Object)

    the value to associate with the supplied header name

Returns:

  • (String)

    the supplied value as a string, or ‘nil` if `nil` was supplied as the value.

See Also:

  • Headers#[]=


46
# File 'lib/stomper/frame.rb', line 46

def []=(name, val); @headers[name] = val; end

#content_typeString

A convenience method for getting the ‘content-type’ header without any parameters.

Returns:

  • (String)


51
52
53
# File 'lib/stomper/frame.rb', line 51

def content_type
  @headers[:'content-type'] && @headers[:'content-type'].split(';').first || ''
end