From e839e4487479b8f74c8bf0adb8a4a266831ce8c8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 17 Jan 2022 11:35:28 -0500 Subject: [PATCH] Use value_semantics to DRY up CustomerRepo --- lib/customer_repo.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/customer_repo.rb b/lib/customer_repo.rb index 940b9b7..39820c3 100644 --- a/lib/customer_repo.rb +++ b/lib/customer_repo.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "lazy_object" +require "value_semantics/monkey_patched" require_relative "customer" require_relative "polyfill" @@ -8,16 +9,11 @@ require_relative "polyfill" class CustomerRepo class NotFound < RuntimeError; end - def initialize( - redis: LazyObject.new { REDIS }, - db: LazyObject.new { DB }, - braintree: LazyObject.new { BRAINTREE }, - sgx_repo: TrivialBackendSgxRepo.new - ) - @redis = redis - @db = db - @braintree = braintree - @sgx_repo = sgx_repo + value_semantics do + redis Anything(), default: LazyObject.new { REDIS } + db Anything(), default: LazyObject.new { DB } + braintree Anything(), default: LazyObject.new { BRAINTREE } + sgx_repo Anything(), default: TrivialBackendSgxRepo.new end def find(customer_id) -- 2.45.2