Class: Tinker::Client
- Inherits:
-
Object
- Object
- Tinker::Client
- Defined in:
- lib/tinker/client.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#initialize(socket) ⇒ Client
constructor
A new instance of Client.
- #join(context) ⇒ Object
- #leave(context) ⇒ Object
- #send(params) ⇒ Object
- #to_json(*a) ⇒ Object
Constructor Details
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
2 3 4 |
# File 'lib/tinker/client.rb', line 2 def id @id end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
2 3 4 |
# File 'lib/tinker/client.rb', line 2 def socket @socket end |
Instance Method Details
#disconnect ⇒ Object
20 21 22 23 24 |
# File 'lib/tinker/client.rb', line 20 def disconnect @contexts.each do |context| context.remove_client(self) end end |
#join(context) ⇒ Object
10 11 12 13 |
# File 'lib/tinker/client.rb', line 10 def join(context) @contexts.add context send(action: 'meta.context.join', context: context.id, params: { type: context.class }) end |
#leave(context) ⇒ Object
15 16 17 18 |
# File 'lib/tinker/client.rb', line 15 def leave(context) @contexts.delete context send(action: 'meta.context.leave', context: context.id, params: { type: context.class }) end |
#send(params) ⇒ Object
32 33 34 |
# File 'lib/tinker/client.rb', line 32 def send(params) socket.send(params) end |
#to_json(*a) ⇒ Object
26 27 28 29 30 |
# File 'lib/tinker/client.rb', line 26 def to_json(*a) { id: id }.to_json(*a) end |