Class: Orator::MiddleGround
- Inherits:
-
Object
- Object
- Orator::MiddleGround
- Defined in:
- lib/orator/middle_ground.rb
Overview
This is used as a context for the client execution.
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
Provides access to the client.
-
#clients ⇒ Set<Client>
readonly
Provides access to the list of clients that are connected.
Instance Method Summary collapse
-
#initialize(client, clients) ⇒ MiddleGround
constructor
Initialize the class.
-
#message(event, data) ⇒ Hash
This builds a message from a hash and an event.
-
#method_missing(method, *args, &block) ⇒ Object
This delegates the rest of the requests to the struct.
-
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Lets ruby know we’re doing some #method_missing magic.
-
#send(data) ⇒ void
This sends a message to the client.
Constructor Details
#initialize(client, clients) ⇒ MiddleGround
Initialize the class.
17 18 19 20 21 |
# File 'lib/orator/middle_ground.rb', line 17 def initialize(client, clients) @client = client @clients = clients @struct = ::Orator::OpenStruct.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
This delegates the rest of the requests to the struct.
48 49 50 51 52 |
# 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 |
Instance Attribute Details
#client ⇒ Client (readonly)
Provides access to the client.
9 10 11 |
# File 'lib/orator/middle_ground.rb', line 9 def client @client end |
#clients ⇒ Set<Client> (readonly)
Provides access to the list of clients that are connected.
14 15 16 |
# File 'lib/orator/middle_ground.rb', line 14 def clients @clients end |
Instance Method Details
#message(event, data) ⇒ Hash
This builds a message from a hash and an event.
37 38 39 40 41 42 43 44 45 |
# File 'lib/orator/middle_ground.rb', line 37 def (event, data) new_data = { "event" => event.to_s } data.each do |k, v| new_data[k.to_s] = v end new_data end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
Lets ruby know we’re doing some #method_missing magic.
55 56 57 |
# 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) ⇒ void
This method returns an undefined value.
This sends a message to the client.
27 28 29 |
# File 'lib/orator/middle_ground.rb', line 27 def send(data) @client.socket.send Oj.dump(data, :mode => :compat) end |