Class: Deepstream::RecordHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/deepstream/record_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ RecordHandler

Returns a new instance of RecordHandler.



7
8
9
10
# File 'lib/deepstream/record_handler.rb', line 7

def initialize(client)
  @client = client
  @records = {}
end

Instance Method Details

#delete(name) ⇒ Object



47
48
49
# File 'lib/deepstream/record_handler.rb', line 47

def delete(name)
  @client.send_message(TOPIC::RECORD, ACTION::DELETE, name) if @records.delete(name)
end

#discard(name) ⇒ Object



43
44
45
# File 'lib/deepstream/record_handler.rb', line 43

def discard(name)
  unsubscribe(name)
end

#get(name, list: nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/deepstream/record_handler.rb', line 22

def get(name, list: nil)
  if list
    name.prepend("#{list}/")
    @records[list] ||= List.new(@client, list)
    @records[list].add(name)
  end
  @records[name] ||= Record.new(@client, name)
end

#get_list(name) ⇒ Object



31
32
33
# File 'lib/deepstream/record_handler.rb', line 31

def get_list(name)
  @records[name] ||= List.new(@client, name)
end

#on_message(message) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/deepstream/record_handler.rb', line 12

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 @client.on_error(message)
  end
end

#set(name, *args) ⇒ Object



35
36
37
# File 'lib/deepstream/record_handler.rb', line 35

def set(name, *args)
  @records[name]&.set(*args)
end

#unsubscribe(name) ⇒ Object



39
40
41
# File 'lib/deepstream/record_handler.rb', line 39

def unsubscribe(name)
  @records[name]&.unsubscribe
end