Class: Metybur::Collection

Inherits:
Object
  • Object
show all
Defined in:
lib/metybur/collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(collection_name, websocket) ⇒ Collection



2
3
4
5
6
7
8
9
# File 'lib/metybur/collection.rb', line 2

def initialize(collection_name, websocket)
  @callbacks = {}

  websocket.on(:message) do |event|
    attributes = JSON.parse(event.data, symbolize_names: true)
    handle_message(attributes) if attributes[:collection] == collection_name
  end
end

Instance Method Details

#on(event, &block) ⇒ Object



11
12
13
14
15
# File 'lib/metybur/collection.rb', line 11

def on(event, &block)
  @callbacks[event] ||= []
  @callbacks[event] << block
  self
end