Class: Deepstream::Record

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

Direct Known Subclasses

List

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of 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



44
45
46
47
48
49
# File 'lib/deepstream.rb', line 44

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

Instance Method Details

#_patch(version, field, value) ⇒ Object



34
35
36
37
# File 'lib/deepstream.rb', line 34

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

#_update(version, data) ⇒ Object



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

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

#set(*args) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/deepstream.rb', line 25

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