Class: Grenache::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/grenache/link.rb

Overview

Implement Grape connection helpers

Instance Method Summary collapse

Instance Method Details

#connectObject

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

Returns:

  • (Boolean)


13
14
15
# File 'lib/grenache/link.rb', line 13

def connected?
  @connected
end

#disconnectObject

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)
    messages[m.rid] = m
    ws_send m.to_json
  end
end