Replace long conditional with guard clauses

This commit is contained in:
Jack Nagel 2013-08-14 14:13:03 -05:00
parent d77240a98c
commit 7ddc432c9e

View File

@ -35,15 +35,11 @@ def python_helper(options={:allowed_major_versions => [2, 3]}, &block)
filtered_python_reqs = [] filtered_python_reqs = []
while !python_reqs.empty? while !python_reqs.empty?
py = python_reqs.shift py = python_reqs.shift
# this is ulgy but Ruby 1.8 has no `uniq! { }` next if filtered_python_reqs.any? { |req| req.binary == py.binary }
if !filtered_python_reqs.map{ |fpr| fpr.binary }.include?(py.binary) && next unless py.satisfied?
py.satisfied? && next unless options[:allowed_major_versions].include?(py.version.major)
options[:allowed_major_versions].include?(py.version.major) && next if (py.optional? || py.recommended?) && build.without?(py.name)
# if optional or recommended then check the build.with? filtered_python_reqs << py
(self.build.with?(py.name) || !(py.optional? || py.recommended?))
then
filtered_python_reqs << py
end
end end
# Allow to use an else-branch like so: `if python do ... end; else ... end` # Allow to use an else-branch like so: `if python do ... end; else ... end`