Class: Metybur::Method
- Inherits:
-
Object
- Object
- Metybur::Method
- Defined in:
- lib/metybur/method.rb
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.
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/metybur/method.rb', line 2 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
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/metybur/method.rb', line 15 def call(params, &block) id = SecureRandom.uuid = { msg: 'method', id: id, method: @name, params: params }.to_json @websocket.send @callbacks[id] = block end |