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.



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

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

Instance Method Details

#delete(name) ⇒ Object



50
51
52
# File 'lib/deepstream/record_handler.rb', line 50

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

#discard(name) ⇒ Object



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

def discard(name)
  unsubscribe(name)
end

#get(name, list: nil) ⇒ Object Also known as: get_record



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

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

#get_list(name) ⇒ Object



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

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

#on_message(message) ⇒ Object



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

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

#set(name, *args) ⇒ Object



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

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

#unsubscribe(name) ⇒ Object



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

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