Class: Wampproto::Message::Hello

Inherits:
Base
  • Object
show all
Defined in:
lib/wampproto/message/hello.rb

Overview

Wamp Hello message

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

type, #type

Constructor Details

#initialize(realm, details = {}) ⇒ Hello

Returns a new instance of Hello.



9
10
11
12
13
# File 'lib/wampproto/message/hello.rb', line 9

def initialize(realm, details = {})
  super()
  @realm = Validate.string!("Realm", realm)
  @details = default_details.merge(parse_details(Validate.hash!("Details", details))).merge(additional_details)
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



7
8
9
# File 'lib/wampproto/message/hello.rb', line 7

def details
  @details
end

#realmObject (readonly)

Returns the value of attribute realm.



7
8
9
# File 'lib/wampproto/message/hello.rb', line 7

def realm
  @realm
end

Class Method Details

.parse(wamp_message) ⇒ Object



28
29
30
31
# File 'lib/wampproto/message/hello.rb', line 28

def self.parse(wamp_message)
  _type, realm, details = wamp_message
  new(realm, details)
end

Instance Method Details

#authextraObject



45
46
47
# File 'lib/wampproto/message/hello.rb', line 45

def authextra
  @authextra ||= details.fetch(:authextra, {})
end

#authidObject



37
38
39
# File 'lib/wampproto/message/hello.rb', line 37

def authid
  @authid ||= details[:authid]
end

#authmethodsObject



41
42
43
# File 'lib/wampproto/message/hello.rb', line 41

def authmethods
  @authmethods ||= details.fetch(:authmethods, [])
end

#marshalObject



15
16
17
# File 'lib/wampproto/message/hello.rb', line 15

def marshal
  [Type::HELLO, @realm, @details]
end

#parse_details(hsh = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/wampproto/message/hello.rb', line 19

def parse_details(hsh = {})
  details = {}
  details[:roles] = hsh.fetch(:roles, default_roles)
  details[:authid] = hsh.fetch(:authid, nil)
  details[:authmethods] = [*hsh.fetch(:authmethods, "anonymous")]
  details[:authextra] = Validate.hash!("AuthExtra", hsh.fetch(:authextra)) if hsh[:authextra]
  details
end

#rolesObject



33
34
35
# File 'lib/wampproto/message/hello.rb', line 33

def roles
  @roles ||= details.fetch(:roles, {})
end