Try to classify URI before saving, even if timeout.zero?

Stephen Paul Weber created

Change summary

.rubocop.yml        |  3 +++
lib/customer_fwd.rb | 16 ++++++++++------
2 files changed, 13 insertions(+), 6 deletions(-)

Detailed changes

.rubocop.yml 🔗

@@ -55,6 +55,9 @@ Layout/LineLength:
   Exclude:
     - Gemfile
 
+Layout/EndAlignment:
+  EnforcedStyleAlignWith: start_of_line
+
 Layout/SpaceAroundEqualsInParameterDefault:
   EnforcedStyle: no_space
 

lib/customer_fwd.rb 🔗

@@ -7,14 +7,18 @@ require "uri"
 class CustomerFwd
 	def self.for(uri:, timeout:)
 		timeout = Timeout.new(timeout)
-		return None.new(uri: uri, timeout: timeout) if !uri || timeout.zero?
 
-		if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/
-			uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}"
+		fwd = if uri
+			if uri =~ /\Asip:(.*)@sip.cheogram.com\Z/
+				uri = "xmpp:#{$1.gsub(/%([0-9A-F]{2})/i) { $1.to_i(16).chr }}"
+			end
+
+			URIS.fetch(uri.split(":", 2).first.to_sym) {
+				raise "Unknown forward URI: #{uri}"
+			}.new(uri: uri, timeout: timeout)
 		end
-		URIS.fetch(uri.split(":", 2).first.to_sym) {
-			raise "Unknown forward URI: #{uri}"
-		}.new(uri: uri, timeout: timeout)
+
+		fwd && !timeout.zero? ? fwd : None.new(uri: uri, timeout: timeout)
 	end
 
 	class Timeout