Class: Metybur::Method
- Inherits:
-
Object
- Object
- Metybur::Method
- Defined in:
- lib/metybur/method.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #call(params, &block) ⇒ Object
-
#initialize(name, websocket) ⇒ Method
constructor
A new instance of Method.
Constructor Details
#initialize(name, websocket) ⇒ Method
Returns a new instance of Method.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/metybur/method.rb', line 28 def initialize(name, websocket) require 'securerandom' @name = name @websocket = websocket @callbacks = {} @websocket.on(:message) do |event| attributes = JSON.parse(event.data, symbolize_names: true) (attributes) if attributes[:msg] == 'result' end end |
Instance Method Details
#call(params, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/metybur/method.rb', line 41 def call(params, &block) id = SecureRandom.uuid = { msg: 'method', id: id, method: @name, params: params }.to_json @websocket.send @callbacks[id] = block end |