Sha256: 5fe55fcb880d791cc15e7a356ffc054a496f05fad6949951fccdceb4884c1c9b
Contents?: true
Size: 1.48 KB
Versions: 3
Compression:
Stored size: 1.48 KB
Contents
require 'deepstream/constants' require 'deepstream/exceptions' require 'deepstream/list' require 'deepstream/record' module Deepstream class RecordHandler def initialize(client) @client = client @records = {} end def on_message(message) case message.action when ACTION::ACK then nil when ACTION::PATCH then patch(message) when ACTION::READ then read(message) when ACTION::UPDATE then update(message) else raise(UnknownAction, message) end end def get(name, list: nil) name = name.dup.to_s if list name.prepend("#{list}/") @records[list] ||= List.new(@client, list) @records[list].add(name) end @records[name] ||= Record.new(@client, name) end alias get_record get def get_list(name) @records[name] ||= List.new(@client, name) end def set(name, *args) @records[name]&.set(*args) end def unsubscribe(name) @records[name]&.unsubscribe end def discard(name) unsubscribe(name) end def delete(name) @client.send_message(TOPIC::RECORD, ACTION::DELETE, name) if @records.delete(name) end private def read(message) name, *data = message.data @records[name]&.read(*data) end def update(message) name, *data = message.data @records[name]&.update(*data) end def patch(message) name, *data = message.data @records[name]&.patch(*data) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
deepstream-0.3.2 | lib/deepstream/record_handler.rb |
deepstream-0.3.1 | lib/deepstream/record_handler.rb |
deepstream-0.3.0 | lib/deepstream/record_handler.rb |