~singpolyma/sgx-jmp

e839e4487479b8f74c8bf0adb8a4a266831ce8c8 — Stephen Paul Weber 1 year, 4 months ago 110a040
Use value_semantics to DRY up CustomerRepo
1 files changed, 6 insertions(+), 10 deletions(-)

M lib/customer_repo.rb
M lib/customer_repo.rb => lib/customer_repo.rb +6 -10
@@ 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)