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



57
58
59
# File 'lib/deepstream/record_handler.rb', line 57

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

#discard(name) ⇒ Object



53
54
55
# File 'lib/deepstream/record_handler.rb', line 53

def discard(name)
  unsubscribe(name)
end

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



30
31
32
33
34
35
36
37
38
# File 'lib/deepstream/record_handler.rb', line 30

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



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

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

#on_message(message) ⇒ Object



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

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

#reinitializeObject



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

def reinitialize
  @records.map do |record|
    name, rec = record
    rec.start_reinitializing
  end
end

#set(name, *args) ⇒ Object



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

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

#unsubscribe(name) ⇒ Object



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

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