Class: Metybur::Collection
- Inherits:
-
Object
- Object
- Metybur::Collection
- Defined in:
- lib/metybur/collection.rb
Instance Method Summary collapse
-
#initialize(collection_name, websocket) ⇒ Collection
constructor
A new instance of Collection.
- #on(event, &block) ⇒ Object
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) (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 |