Skip to content

Commit

Permalink
Reduce complexity reported by codeclimate
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Feb 26, 2024
1 parent 999a121 commit 2af525f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/puffy/formatters/pf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,21 @@ def emit_address(host, if_unspecified = 'any')
def emit_rdr_to(rule)
return unless rule.rdr?

keyword = Puffy::Formatters::Base.loopback_addresses.include?(rule.rdr_to_host) ? 'divert-to' : 'rdr-to'
keyword = rdr_to_keyword(rule)
destination = rule.rdr_to_host || loopback_address(rule.af)
raise 'Unspecified address family' if destination.nil?

emit_endpoint_specification(keyword, destination, rule.rdr_to_port)
end

def rdr_to_keyword(rule)
if Puffy::Formatters::Base.loopback_addresses.include?(rule.rdr_to_host)
'divert-to'
else
'rdr-to'
end
end

def emit_nat_to(rule)
"nat-to #{emit_address(rule.nat_to)}" if rule.nat_to
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puffy/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class Rule
def initialize(options = {})
send_options(options)

@af = detect_af unless af

self.af ||= detect_af
self.proto ||= from_proto_hint || to_proto_hint

raise "unsupported action `#{options[:action]}'" unless valid_action?
Expand Down

0 comments on commit 2af525f

Please sign in to comment.