Class: Orator::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/orator/client.rb

Overview

A representation of a client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Client

Initialize.

Examples:

client = Client.new :something => "foo"
client.something # => "foo"

Parameters:

  • data (Hash)

    the keys are used to set data on the client to the values of the hash. If the attribute doesn’t exist on the client, it is ignored.



29
30
31
32
33
# File 'lib/orator/client.rb', line 29

def initialize(data)
  data.each do |k, v|
    send "#{k}=", v if respond_to? "#{k}="
  end
end

Instance Attribute Details

#contextObject

The context to be used by the client.

Returns:

  • (Object)


14
15
16
# File 'lib/orator/client.rb', line 14

def context
  @context
end

#event_handlerEventHandler

The event handler for this client.

Returns:



9
10
11
# File 'lib/orator/client.rb', line 9

def event_handler
  @event_handler
end

#socket#send

The socket to be used to talk to the client.

Returns:

  • (#send)


19
20
21
# File 'lib/orator/client.rb', line 19

def socket
  @socket
end

Instance Method Details

#to_hashHash

This is here just in case anyone gets the bright idea to serialize the client with Oj. This should not happen, because it could reveal information that you may not want to be revealed.

Returns:

  • (Hash)


48
49
50
# File 'lib/orator/client.rb', line 48

def to_hash
  context.table
end

#trigger(event, *args) ⇒ Object

This forwards the method call to [EventHandler#trigger], but removes an argument: the context.

See Also:

  • Orator::Client.[EventHandler[EventHandler#trigger]


39
40
41
# File 'lib/orator/client.rb', line 39

def trigger(event, *args)
  event_handler.trigger(event, context, *args)
end