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.
-
#initialize(config) ⇒ Link
constructor
Initialize passing configuration.
-
#send(type, payload, opts = {}, &block) ⇒ Object
Send a message to grape.
Constructor Details
#initialize(config) ⇒ Link
Initialize passing configuration
6 7 8 |
# File 'lib/grenache/link.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#connect ⇒ Object
Connect to grape
11 12 13 14 15 |
# File 'lib/grenache/link.rb', line 11 def connect unless connected? ws_connect end end |
#connected? ⇒ Boolean
Return true if it’s connected to Grape
18 19 20 |
# File 'lib/grenache/link.rb', line 18 def connected? @connected end |
#disconnect ⇒ Object
Disconnect from grape
23 24 25 26 |
# File 'lib/grenache/link.rb', line 23 def disconnect @ws.close @ws = nil end |
#send(type, payload, opts = {}, &block) ⇒ Object
Send a message to grape
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/grenache/link.rb', line 29 def send(type, payload, opts = {}, &block) if http? res = http_send type, Oj.dump({"rid" => uuid, "data" => payload}) block.call(res) if block res else m = GrapeMessage.new(type,payload,opts, &block) [m.rid] = m ws_send m.to_json end end |