lib/bundler/audit/scanner.rb in mrjoy-bundler-audit-0.3.1 vs lib/bundler/audit/scanner.rb in mrjoy-bundler-audit-0.3.2

- old
+ new

@@ -60,38 +60,50 @@ # If no block is given, an Enumerator will be returned. # def scan(options={}) return enum_for(__method__,options) unless block_given? - ignore = Set[] - ignore += options[:ignore] if options[:ignore] + get_insecure_sources.each { |source| yield source } + get_unpatched_gems(options[:ignore]).each { |gem| yield gem } - @lockfile.sources.map do |source| + return self + end + + protected + + def get_insecure_sources + insecure = [] + @lockfile.sources.each do |source| case source when Source::Git - case source.uri - when /^git:/, /^http:/ - yield InsecureSource.new(source.uri) - end + next unless(source.uri =~ /^(git|http):/) + + insecure << InsecureSource.new(source.uri) when Source::Rubygems - source.remotes.each do |uri| - if uri.scheme == 'http' - yield InsecureSource.new(uri.to_s) - end + source.remotes.map do |uri| + next unless uri.scheme == 'http' + + insecure << InsecureSource.new(uri.to_s) end end end + return insecure + end + + def get_unpatched_gems(ignore) + ignore = Set.new(ignore) # If ignore is empty the Set will contain nil, + # but since we should never have a nil version + # that's a non-issue. + unpatched = [] @lockfile.specs.each do |gem| @database.check_gem(gem) do |advisory| - unless ignore.include?(advisory.id) - yield UnpatchedGem.new(gem,advisory) - end + next if ignore.include?(advisory.id) + + unpatched << UnpatchedGem.new(gem,advisory) end end - - return self + return unpatched end - end end end