Skip to content

Commit

Permalink
rubocop: Fix Style/GuardClause
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Nov 22, 2024
1 parent ba19589 commit 846d528
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
24 changes: 12 additions & 12 deletions lib/whois.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,24 @@ def bug!(error, message)

def deprecation_caller_message(callstack)
file, line, method = extract_callstack(callstack)
if file
if line && method
"(called from #{method} at #{file}:#{line})"
else
"(called from #{file}:#{line})"
end
return unless file

if line && method
"(called from #{method} at #{file}:#{line})"
else
"(called from #{file}:#{line})"
end
end

def extract_callstack(callstack)
gem_root = "#{File.expand_path('../..', __dir__)}/"
offending_line = callstack.find { |line| !line.start_with?(gem_root) } || callstack.first
if offending_line
if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
md.captures
else
offending_line
end
return unless offending_line

if (md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/))
md.captures
else
offending_line
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/whois/server/adapters/arpa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ def inaddr_to_ip(string)
a, b, c, d = string.scan(/[0-9]{1,3}\./).reverse
[a, b, c, d].map do |token|
token = (token || 0).to_i
if token <= 255 && token >= 0
token
else
raise ServerError, "Invalid .in-addr.arpa token `#{token}'"
end
raise ServerError, "Invalid .in-addr.arpa token `#{token}'" unless token <= 255 && token >= 0

token
end.join(".")
end

Expand Down

0 comments on commit 846d528

Please sign in to comment.