Class: Deepstream::List

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

Instance Method Summary collapse

Methods inherited from Record

#_patch, #_update, #get_name, #initialize, #method_missing

Constructor Details

This class inherits a constructor from Deepstream::Record

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Deepstream::Record

Instance Method Details

#add(record_name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/deepstream.rb', line 66

def add(record_name)
  @data = [] unless @data.is_a?(Array)
  unless @data.include? record_name
    @data.push record_name
    @client._write('R', 'U', @name, (@version += 1), JSON.dump(@data))
  end
  @data
rescue => e
  print "unable to add ", @data.pop, "\n"
  print "Error: ", e.message, "\n" if @client.verbose
  @data
end

#allObject



90
91
92
# File 'lib/deepstream.rb', line 90

def all
  @data.map { |x| @client.get_record(x) }
end

#inspectObject



102
103
104
# File 'lib/deepstream.rb', line 102

def inspect
  "Deepstream::List (#{@version}) #{@name} keys: #{@data}"
end

#keysObject



94
95
96
# File 'lib/deepstream.rb', line 94

def keys
  @data
end

#remove(record_name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/deepstream.rb', line 79

def remove(record_name)
  @data.delete_if { |x| x == record_name }
  @client._write('R', 'U', @name, (@version += 1), JSON.dump(@data))
  @data
rescue => e
  print "unable to remove ", record_name, "\n"
  @data.push record_name
  print "Error: ", e.message, "\n" if @client.verbose
  @data
end

#set(*args) ⇒ Object



98
99
100
# File 'lib/deepstream.rb', line 98

def set(*args)
  fail 'cannot use set on a list'
end