~singpolyma/sgx-jmp

18258dd4fe0cbf048cc0fd96494461bef0964cb1 — Stephen Paul Weber 2 years ago 016d8c4
Try to classify URI before saving, even if timeout.zero?
2 files changed, 13 insertions(+), 6 deletions(-)

M .rubocop.yml
M lib/customer_fwd.rb
M .rubocop.yml => .rubocop.yml +3 -0
@@ 55,6 55,9 @@ Layout/LineLength:
  Exclude:
    - Gemfile

Layout/EndAlignment:
  EnforcedStyleAlignWith: start_of_line

Layout/SpaceAroundEqualsInParameterDefault:
  EnforcedStyle: no_space


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