Class: WebSocket::Frame::Base Abstract

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

Overview

This class is abstract.

Subclass and override to implement custom frames

Direct Known Subclasses

Incoming, Outgoing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Base

Initialize frame

Options Hash (args):

  • :data (String)

    default data for frame

  • :type (String)

    Type of frame - available types are “text”, “binary”, “ping”, “pong” and “close”(support depends on draft version)

  • :version (Integer)

    Version of draft. Currently supported version are 75, 76 and 00-13.



13
14
15
16
17
18
# File 'lib/websocket/frame/base.rb', line 13

def initialize(args = {})
  @type = args[:type]
  @data = Data.new(args[:data].to_s)
  @version = args[:version] || DEFAULT_VERSION
  include_version
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/websocket/frame/base.rb', line 6

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



6
7
8
# File 'lib/websocket/frame/base.rb', line 6

def error
  @error
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/websocket/frame/base.rb', line 6

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/websocket/frame/base.rb', line 6

def version
  @version
end

Instance Method Details

#error?Boolean

Check if some errors occured



22
23
24
# File 'lib/websocket/frame/base.rb', line 22

def error?
  !!@error
end

#inspectObject

Recreate inspect as #to_s was overwritten



37
38
39
40
41
# File 'lib/websocket/frame/base.rb', line 37

def inspect
  vars = self.instance_variables.map{|v| "#{v}=#{instance_variable_get(v).inspect}"}.join(", ")
  insp = "#{self.class}:0x%08x" % (self.__id__ * 2)
  "<#{insp} #{vars}>"
end

#support_type?Boolean

Is selected type supported for selected handler?



27
28
29
# File 'lib/websocket/frame/base.rb', line 27

def support_type?
  supported_frames.include?(@type)
end

#supported_framesObject

Implement in submodules

Raises:

  • (NotImplementedError)


32
33
34
# File 'lib/websocket/frame/base.rb', line 32

def supported_frames
  raise NotImplementedError
end