Skip to content

Commit

Permalink
Favor raise to fail.
Browse files Browse the repository at this point in the history
Policy seems to have changed recently
rubocop/rubocop#2732 (comment)
  • Loading branch information
smortex committed Mar 13, 2016
1 parent f8729d7 commit 9c88fef
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/melt/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def ruleset_for(hostname)
# @param hostname [String]
# @return [Symbol]
def policy_for(hostname)
fail "Policy for #{hostname} unknown" unless @saved_policies[hostname]
raise "Policy for #{hostname} unknown" unless @saved_policies[hostname]
@saved_policies[hostname]
end

Expand Down Expand Up @@ -153,7 +153,7 @@ def service(name, &block)
if block_given?
@services[name] = block
else
fail "Undefined service \"#{name}\"" unless @services[name]
raise "Undefined service \"#{name}\"" unless @services[name]
@services[name].call
end
end
Expand Down Expand Up @@ -184,10 +184,10 @@ def bloc_for(hostname)
def block_matching(hostname)
found = nil
@hosts.select { |host, _block| host.is_a?(Regexp) }.each do |_host, block|
fail "Multiple host definition match \"#{hostname}\"" if found
raise "Multiple host definition match \"#{hostname}\"" if found
found = block
end
fail "No host definition match \"#{hostname}\"" unless found
raise "No host definition match \"#{hostname}\"" unless found
found
end

Expand Down
4 changes: 2 additions & 2 deletions lib/melt/formatters/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def emit_ruleset(rules, _policy = nil)
#
# @return [Array<String>]
def filename_fragment
fail 'Formatters#filename_fragment MUST be overriden'
raise 'Formatters#filename_fragment MUST be overriden'
end

protected
Expand All @@ -33,7 +33,7 @@ def loopback_address(address_family)
when :inet then loopback_ipv4
when :inet6 then loopback_ipv6
when nil then nil
else fail "Unsupported address family #{address_family.inspect}"
else raise "Unsupported address family #{address_family.inspect}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/melt/formatters/pf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def emit_rdr_to(rule)
if rule.rdr?
keyword = @loopback_addresses.include?(rule.rdr_to_host) ? 'divert-to' : 'rdr-to'
destination = rule.rdr_to_host || loopback_address(rule.af)
fail 'Unspecified address family' if destination.nil?
raise 'Unspecified address family' if destination.nil?
emit_endpoint_specification(keyword, destination, rule.rdr_to_port)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/melt/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def resolv_hostname(hostname, address_family)
result = []
result += resolv_hostname_ipv6(hostname) if address_family.nil? || address_family == :inet6
result += resolv_hostname_ipv4(hostname) if address_family.nil? || address_family == :inet
fail "\"#{hostname}\" does not resolve to any valid IP#{@af_str[address_family]} address." if result.empty?
raise "\"#{hostname}\" does not resolve to any valid IP#{@af_str[address_family]} address." if result.empty?
result
end

Expand Down
2 changes: 1 addition & 1 deletion lib/melt/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(options = {})
send("#{k}=", v)
end

fail 'if src_port or dst_port is specified, the protocol must also be given' if (src_port || dst_port) && proto.nil?
raise 'if src_port or dst_port is specified, the protocol must also be given' if (src_port || dst_port) && proto.nil?
end

# Instanciate a forward Melt::Rule.
Expand Down
6 changes: 3 additions & 3 deletions lib/melt/rule_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ def initialize

# Limit the scope of a set of rules to IPv4 only.
def ipv4
fail 'Address familly already scopped' if @af
raise 'Address familly already scopped' if @af
@af = :inet
yield
@af = nil
end

# Limit the scope of a set of rules to IPv6 only.
def ipv6
fail 'Address familly already scopped' if @af
raise 'Address familly already scopped' if @af
@af = :inet6
yield
@af = nil
Expand Down Expand Up @@ -112,7 +112,7 @@ def port_loockup(port)
if port.is_a?(Fixnum) || port =~ /^\d+:\d+$/
port
else
fail "unknown service \"#{port}\"" unless @services[port]
raise "unknown service \"#{port}\"" unless @services[port]
@services[port]
end
end
Expand Down

0 comments on commit 9c88fef

Please sign in to comment.