Class: RiakDt::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/riak-dt-ruby/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Set

Returns a new instance of Set.



4
5
6
7
# File 'lib/riak-dt-ruby/set.rb', line 4

def initialize(name)
  self.name = name
  @encoded_name = CGI.escape name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/riak-dt-ruby/set.rb', line 3

def name
  @name
end

Instance Method Details

#add(atom) ⇒ Object



9
10
11
12
# File 'lib/riak-dt-ruby/set.rb', line 9

def add(atom)
  RiakDt.client.post "/sets/#{@encoded_name}/add", atom
  nil
end

#contentsObject



19
20
21
22
23
24
25
26
# File 'lib/riak-dt-ruby/set.rb', line 19

def contents
  response = RiakDt.client.get("/sets/#{@encoded_name}")
  return ::Set.new if response.status == 404
  
  parsed = JSON.parse response.body
  array = parsed[name]
  ::Set.new array
end

#remove(atom) ⇒ Object



14
15
16
17
# File 'lib/riak-dt-ruby/set.rb', line 14

def remove(atom)
  RiakDt.client.post "/sets/#{@encoded_name}/remove", atom
  nil
end