Class: RiakDt::Counter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Counter

Returns a new instance of Counter.



4
5
6
7
# File 'lib/riak-dt-ruby/counter.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/counter.rb', line 3

def name
  @name
end

Instance Method Details

#decrementObject



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

def decrement
  RiakDt.client.post "/counters/#{@encoded_name}/decrement"
  nil
end

#incrementObject



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

def increment
  RiakDt.client.post "/counters/#{@encoded_name}/increment"
  nil
end

#valueObject



19
20
21
22
23
# File 'lib/riak-dt-ruby/counter.rb', line 19

def value
  response = RiakDt.client.get("/counters/#{@encoded_name}")
  return 0 if response.status == 404
  return Integer(response.body)
end