class Orator::MiddleGround

This is used as a context for the client execution.

Attributes

client[R]

Provides access to the client.

@return [Client]

clients[R]

Provides access to the list of clients that are connected.

@return [Set<Client>]

Public Class Methods

new(client, clients) click to toggle source

Initialize the class.

# File lib/orator/middle_ground.rb, line 17
def initialize(client, clients)
  @client  = client
  @clients = clients
  @struct  = ::Orator::OpenStruct.new
end

Public Instance Methods

message(event, data) click to toggle source

This builds a message from a hash and an event.

@param event [String, Symbol] the event for the message. @param data [Hash] the data for the message.

@return [Hash]

# File lib/orator/middle_ground.rb, line 37
def message(event, data)
  new_data = { "event" => event.to_s }

  data.each do |k, v|
    new_data[k.to_s] = v
  end

  new_data
end
method_missing(method, *args, &block) click to toggle source

This delegates the rest of the requests to the struct.

Calls superclass method
# File lib/orator/middle_ground.rb, line 48
def method_missing(method, *args, &block)
  super unless respond_to_missing?(method)

  @struct.public_send(method, *args, &block)
end
respond_to_missing?(method, include_private = false) click to toggle source

Lets ruby know we’re doing some {#method_missing} magic.

# File lib/orator/middle_ground.rb, line 55
def respond_to_missing?(method, include_private = false)
  @struct.respond_to?(method, include_private)
end
send(data) click to toggle source

This sends a message to the client.

@param data [Hash] the data to be sent to the client. @return [void]

# File lib/orator/middle_ground.rb, line 27
def send(data)
  @client.socket.send Oj.dump(data, :mode => :compat)
end