Class: Deepstream::Record
- Inherits:
-
Object
- Object
- Deepstream::Record
show all
- Defined in:
- lib/deepstream/record.rb
Direct Known Subclasses
List
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client, name) ⇒ Record
Returns a new instance of Record.
9
10
11
12
13
14
15
|
# File 'lib/deepstream/record.rb', line 9
def initialize(client, name)
@client = client
@name = name
@data = {}
@version = nil
@client.send_message(TOPIC::RECORD, ACTION::CREATEORREAD, @name)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
54
55
56
57
|
# File 'lib/deepstream/record.rb', line 54
def method_missing(name, *args)
return @data.fetch(name.to_s, nil) if args.empty?
raise(NoMethodError, name)
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7
8
9
|
# File 'lib/deepstream/record.rb', line 7
def data
@data
end
|
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/deepstream/record.rb', line 7
def name
@name
end
|
#version ⇒ Object
Returns the value of attribute version.
7
8
9
|
# File 'lib/deepstream/record.rb', line 7
def version
@version
end
|
Instance Method Details
#delete ⇒ Object
25
26
27
|
# File 'lib/deepstream/record.rb', line 25
def delete
@client.delete(@name)
end
|
#inspect ⇒ Object
17
18
19
|
# File 'lib/deepstream/record.rb', line 17
def inspect
"#{self.class} #{@name} #{@version} #{@data}"
end
|
#patch(version, path, value) ⇒ Object
44
45
46
47
|
# File 'lib/deepstream/record.rb', line 44
def patch(version, path, value)
@version = version.to_i
set_path(@data, path, Helpers.to_type(value))
end
|
#read(version, data) ⇒ Object
40
41
42
|
# File 'lib/deepstream/record.rb', line 40
def read(version, data)
update(version, data)
end
|
#set(*args) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/deepstream/record.rb', line 29
def set(*args)
if args.one?
@data = args.first
@client.send_message(TOPIC::RECORD, ACTION::UPDATE, @name, (@version += 1), @data.to_json) if @version
elsif args.size == 2
path, value = args
set_path(@data, path, value)
@client.send_message(TOPIC::RECORD, ACTION::PATCH, @name, (@version += 1), path, Helpers.to_deepstream_type(value)) if @version
end
end
|
#update(version, data) ⇒ Object
49
50
51
52
|
# File 'lib/deepstream/record.rb', line 49
def update(version, data)
@version = version.to_i
@data = JSON.parse(data)
end
|