Class: Deepstream::Record
- Inherits:
-
Object
- Object
- Deepstream::Record
- Defined in:
- lib/deepstream.rb
Direct Known Subclasses
Instance Method Summary collapse
- #_patch(version, field, value) ⇒ Object
- #_update(version, data) ⇒ Object
- #get_name ⇒ Object
-
#initialize(client, name, data, version) ⇒ Record
constructor
A new instance of Record.
- #inspect ⇒ Object
- #method_missing(name, *args) ⇒ Object
- #set(*args) ⇒ Object
Constructor Details
#initialize(client, name, data, version) ⇒ Record
21 22 23 |
# File 'lib/deepstream.rb', line 21 def initialize(client, name, data, version) @client, @name, @data, @version = client, name, data, version end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/deepstream.rb', line 53 def method_missing(name, *args) unless @data.is_a?(Array) set(name, *args) if name[-1] == '=' @data[name] || @data[name[-1]] end end |
Instance Method Details
#_patch(version, field, value) ⇒ Object
43 44 45 46 |
# File 'lib/deepstream.rb', line 43 def _patch(version, field, value) @version = version.to_i @data[field] = value end |
#_update(version, data) ⇒ Object
48 49 50 51 |
# File 'lib/deepstream.rb', line 48 def _update(version, data) @version = version.to_i @data = data end |
#get_name ⇒ Object
25 26 27 |
# File 'lib/deepstream.rb', line 25 def get_name @name end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/deepstream.rb', line 60 def inspect "Deepstream::Record (#{@version}) #{@name} #{@data.to_h}" end |
#set(*args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/deepstream.rb', line 29 def set(*args) if args.size == 1 if @client._write('R', 'U', @name, (@version += 1), JSON.dump(args[0])) @data = OpenStruct.new(args[0]) end else @client._write('R', 'P', @name, (@version += 1), args[0][0..-2], @client._typed(args[1])) @data[args[0][0..-2]] = args[1] end rescue => e print "unable to set\n" print "Error: ", e., "\n" if @client.verbose end |