Class: Deepstream::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/deepstream.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, name, data, version) ⇒ Record



25
26
27
# File 'lib/deepstream.rb', line 25

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



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

def method_missing(name, *args)
  set(name, *args) if name[-1] == '='
  @data.send(name, *args)
end

Instance Method Details

#_patch(version, field, value) ⇒ Object



38
39
40
41
# File 'lib/deepstream.rb', line 38

def _patch(version, field, value)
  @version = version.to_i
  @data[field] = value
end

#_update(version, data) ⇒ Object



43
44
45
46
# File 'lib/deepstream.rb', line 43

def _update(version, data)
  @version = version.to_i
  @data = data
end

#set(*args) ⇒ Object



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

def set(*args)
  if args.size == 1
    @client._write('R', 'U', @name, (@version += 1), JSON.dump(args[0]))
    @data = OpenStruct.new(args[0])
  else
    @client._write('R', 'P', @name, (@version += 1), args[0][0..-2], @client._typed(args[1]))
  end
end