Need repo too during bill plan command

Stephen Paul Weber created

Change summary

lib/db_notification.rb | 4 ++--
lib/dummy_command.rb   | 5 +++--
sgx_jmp.rb             | 8 ++++----
3 files changed, 9 insertions(+), 8 deletions(-)

Detailed changes

lib/db_notification.rb 🔗

@@ -3,12 +3,12 @@
 require_relative "dummy_command"
 
 module DbNotification
-	def self.for(notify, customer)
+	def self.for(notify, customer, customer_repo)
 		case notify[:relname]
 		when "low_balance"
 			LowBalance.for(customer).then { |lb| lb.method(:notify!) }
 		when "possible_renewal"
-			Command.execution = DummyCommand.new(customer)
+			Command.execution = DummyCommand.new(customer, customer_repo)
 			BillPlanCommand.for(customer)
 		else
 			raise "Unknown notification: #{notify[:relname]}"

lib/dummy_command.rb 🔗

@@ -1,10 +1,11 @@
 # frozen_string_literal: true
 
 class DummyCommand
-	attr_reader :customer
+	attr_reader :customer, :customer_repo
 
-	def initialize(customer)
+	def initialize(customer, customer_repo)
 		@customer = customer
+		@customer_repo = customer_repo
 	end
 
 	def reply(*); end

sgx_jmp.rb 🔗

@@ -196,10 +196,10 @@ end
 
 def poll_for_notify(db)
 	db.wait_for_notify_defer.then { |notify|
-		CustomerRepo
-			.new(sgx_repo: Bwmsgsv2Repo.new)
-			.find(notify[:extra])
-			.then { |customer| DbNotification.for(notify, customer) }
+		repo = CustomerRepo.new(sgx_repo: Bwmsgsv2Repo.new)
+		repo.find(notify[:extra]).then do |customer|
+			DbNotification.for(notify, customer, repo)
+		end
 	}.then(&:call).then {
 		poll_for_notify(db)
 	}.catch(&method(:panic))