Class: Grenache::Link
- Inherits:
-
Object
- Object
- Grenache::Link
- Defined in:
- lib/grenache/link.rb
Overview
Implement Grape connection helpers
Instance Method Summary collapse
-
#connect ⇒ Object
Connect to grape.
-
#connected? ⇒ Boolean
Return true if it’s connected to Grape.
-
#disconnect ⇒ Object
Disconnect from grape.
-
#send(type, payload, opts = {}, &block) ⇒ Object
Send a message to grape.
Instance Method Details
#connect ⇒ Object
Connect to grape
6 7 8 9 10 |
# File 'lib/grenache/link.rb', line 6 def connect unless connected? ws_connect end end |
#connected? ⇒ Boolean
Return true if it’s connected to Grape
13 14 15 |
# File 'lib/grenache/link.rb', line 13 def connected? @connected end |
#disconnect ⇒ Object
Disconnect from grape
18 19 20 21 |
# File 'lib/grenache/link.rb', line 18 def disconnect @ws.close @ws = nil end |
#send(type, payload, opts = {}, &block) ⇒ Object
Send a message to grape
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/grenache/link.rb', line 24 def send(type, payload, opts = {}, &block) if http? res = http_send type, Oj.dump({"rid" => 1234, "data" => payload}) block.call(res) if block res else m = Message.new(type,payload,opts, &block) [m.rid] = m ws_send m.to_json end end |