Class: Deepstream::Record
- Inherits:
-
Object
- Object
- Deepstream::Record
- Defined in:
- lib/deepstream/record.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(client, name) ⇒ Record
constructor
A new instance of Record.
- #inspect ⇒ Object
- #patch(version, path, value) ⇒ Object
- #read(version, data) ⇒ Object
- #set(*args) ⇒ Object
- #unsubscribe ⇒ Object
- #update(version, data) ⇒ Object
Constructor Details
#initialize(client, name) ⇒ Record
Returns a new instance of Record.
9 10 11 12 13 14 |
# File 'lib/deepstream/record.rb', line 9 def initialize(client, name) @client = client @name = name @data, @version = nil @client.(TOPIC::RECORD, ACTION::CREATEORREAD, @name) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/deepstream/record.rb', line 7 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/deepstream/record.rb', line 7 def name @name end |
#version ⇒ Object (readonly)
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
24 25 26 |
# File 'lib/deepstream/record.rb', line 24 def delete @client.delete(@name) end |
#inspect ⇒ Object
16 17 18 |
# File 'lib/deepstream/record.rb', line 16 def inspect "#{self.class} #{@name} #{@version} #{@data}" end |
#patch(version, path, value) ⇒ Object
43 44 45 46 |
# File 'lib/deepstream/record.rb', line 43 def patch(version, path, value) @version = version.to_i set_path(@data, path, Helpers.to_type(value)) end |
#read(version, data) ⇒ Object
39 40 41 |
# File 'lib/deepstream/record.rb', line 39 def read(version, data) update(version, data) end |
#set(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deepstream/record.rb', line 28 def set(*args) if args.one? @data = args.first @client.(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.(TOPIC::RECORD, ACTION::PATCH, @name, (@version += 1), path, Helpers.to_deepstream_type(value)) if @version end end |
#unsubscribe ⇒ Object
20 21 22 |
# File 'lib/deepstream/record.rb', line 20 def unsubscribe @client.(TOPIC::RECORD, ACTION::UNSUBSCRIBE, name) end |
#update(version, data) ⇒ Object
48 49 50 51 |
# File 'lib/deepstream/record.rb', line 48 def update(version, data) @version = version.to_i @data = JSON.parse(data) end |