lib/moneta/adapters/pstore.rb in moneta-0.7.3 vs lib/moneta/adapters/pstore.rb in moneta-0.7.4
- old
+ new
@@ -4,10 +4,11 @@
module Adapters
# PStore backend
# @api public
class PStore
include Defaults
+ include IncrementSupport
# @param [Hash] options
# @option options [String] :file PStore file
def initialize(options = {})
raise ArgumentError, 'Option :file is required' unless options[:file]
@@ -36,15 +37,12 @@
end
# (see Proxy#increment)
def increment(key, amount = 1, options = {})
@pstore.transaction do
- value = @pstore[key]
- intvalue = value.to_i
- raise 'Tried to increment non integer value' unless value == nil || intvalue.to_s == value.to_s
- intvalue += amount
- @pstore[key] = intvalue.to_s
- intvalue
+ value = convert_for_increment(@pstore[key]) + amount
+ @pstore[key] = value.to_s
+ value
end
end
# (see Proxy#clear)
def clear(options = {})