refactor: protect max_declines

Amolith created

Change summary

lib/trust_level.rb | 90 +++++++++++++++++++++++++----------------------
1 file changed, 48 insertions(+), 42 deletions(-)

Detailed changes

lib/trust_level.rb 🔗

@@ -32,12 +32,6 @@ module TrustLevel
 			new if manual == "Tomb"
 		end
 
-		# The maximum amount a user at Tomb trust level can top up.
-		# @return [Integer] Always 0 for Tomb level.
-		def max_top_up_amount
-			0
-		end
-
 		def write_cdr?
 			false
 		end
@@ -67,6 +61,12 @@ module TrustLevel
 		def to_s
 			"Tomb"
 		end
+
+		# The maximum amount a user at Tomb trust level can top up.
+		# @return [Integer] Always 0 for Tomb level.
+		def max_top_up_amount
+			0
+		end
 	end
 
 	class Basement
@@ -74,19 +74,6 @@ module TrustLevel
 			new if manual == "Basement" || (!manual && settled_amount < 10)
 		end
 
-		# The maximum amount a user at Basement trust level can top up.
-		# @return [Integer]
-		def max_top_up_amount
-			35
-		end
-
-		# The maximum number of credit card declines allowed for a Basement user
-		# before further transactions are blocked.
-		# @return [Integer]
-		def max_declines
-			2
-		end
-
 		def write_cdr?
 			true
 		end
@@ -118,24 +105,26 @@ module TrustLevel
 		def to_s
 			"Basement"
 		end
-	end
 
-	class Paragon
-		TrustLevel.register do |manual:, settled_amount:, **|
-			new if manual == "Paragon" || (!manual && settled_amount > 60)
-		end
-
-		# The maximum amount a user at Paragon trust level can top up.
+		# The maximum amount a user at Basement trust level can top up.
 		# @return [Integer]
 		def max_top_up_amount
-			500
+			35
 		end
 
-		# The maximum number of credit card declines allowed for a Paragon user
+	protected
+
+		# The maximum number of credit card declines allowed for a Basement user
 		# before further transactions are blocked.
 		# @return [Integer]
 		def max_declines
-			3
+			2
+		end
+	end
+
+	class Paragon
+		TrustLevel.register do |manual:, settled_amount:, **|
+			new if manual == "Paragon" || (!manual && settled_amount > 60)
 		end
 
 		def write_cdr?
@@ -169,6 +158,21 @@ module TrustLevel
 		def to_s
 			"Paragon"
 		end
+
+		# The maximum amount a user at Paragon trust level can top up.
+		# @return [Integer]
+		def max_top_up_amount
+			500
+		end
+
+	protected
+
+		# The maximum number of credit card declines allowed for a Paragon user
+		# before further transactions are blocked.
+		# @return [Integer]
+		def max_declines
+			3
+		end
 	end
 
 	class Olympias
@@ -224,19 +228,6 @@ module TrustLevel
 			@max_rate = EXPENSIVE_ROUTE.fetch(plan_name, 0.1)
 		end
 
-		# The maximum amount a user at Customer trust level can top up.
-		# @return [Integer]
-		def max_top_up_amount
-			130
-		end
-
-		# The maximum number of credit card declines allowed for a Customer user
-		# before further transactions are blocked.
-		# @return [Integer]
-		def max_declines
-			2
-		end
-
 		def write_cdr?
 			true
 		end
@@ -268,5 +259,20 @@ module TrustLevel
 		def to_s
 			"Customer"
 		end
+
+		# The maximum amount a user at Customer trust level can top up.
+		# @return [Integer]
+		def max_top_up_amount
+			130
+		end
+
+	protected
+
+		# The maximum number of credit card declines allowed for a Customer user
+		# before further transactions are blocked.
+		# @return [Integer]
+		def max_declines
+			2
+		end
 	end
 end