Class: Deepstream::List
Instance Attribute Summary
Attributes inherited from Record
#data, #name, #version
Instance Method Summary
collapse
Methods inherited from Record
#delete, #inspect, #patch, #set, #unsubscribe, #update
Constructor Details
#initialize(*args) ⇒ List
Returns a new instance of List.
5
6
7
8
|
# File 'lib/deepstream/list.rb', line 5
def initialize(*args)
super
@data = []
end
|
Instance Method Details
#add(record_name) ⇒ Object
10
11
12
|
# File 'lib/deepstream/list.rb', line 10
def add(record_name)
set(@data.length.to_s, record_name) unless @data.include?(record_name)
end
|
#all ⇒ Object
31
32
33
|
# File 'lib/deepstream/list.rb', line 31
def all
@data.map { |record_name| @client.get(record_name) }
end
|
#keys ⇒ Object
27
28
29
|
# File 'lib/deepstream/list.rb', line 27
def keys
@data
end
|
#read(version, data) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/deepstream/list.rb', line 14
def read(version, data)
@version = version.to_i
data = JSON.parse(data)
if data.is_a?(Array)
@data.concat(data).uniq!
set(@data) if @data.size > data.size
end
end
|
#remove(record_name) ⇒ Object
23
24
25
|
# File 'lib/deepstream/list.rb', line 23
def remove(record_name)
set(@data) if @data.delete(record_name)
end
|