~singpolyma/jmp-pay

ref: 7958c1c5bb43796c0d02663965eee8c89112b812 jmp-pay/lib/auto_top_up_repo.rb -rw-r--r-- 482 bytes
7958c1c5Stephen Paul Weber Factor out AutoTopUpRepo and add tests 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

class AutoTopUpRepo
	def initialize(redis: REDIS, db: DB)
		@redis = redis
		@db = db
	end

	def find(customer_id)
		redis(:get, customer_id)
	end

	def put(customer_id, amount)
		if amount >= 15
			redis(:set, customer_id, amount)
		elsif amount.zero?
			redis(:del, customer_id)
		end
	end

protected

	def redis(action, customer_id, *args)
		@redis.public_send(
			action,
			"jmp_customer_auto_top_up_amount-#{customer_id}",
			*args
		)
	end
end