diff --git a/lib/bundler/audit/scanner.rb b/lib/bundler/audit/scanner.rb index 174de12e..8aec29f2 100644 --- a/lib/bundler/audit/scanner.rb +++ b/lib/bundler/audit/scanner.rb @@ -12,7 +12,9 @@ class Scanner InsecureSource = Struct.new(:source) # Represents a gem that is covered by an Advisory - UnpatchedGem = Struct.new(:gem, :advisory) + UnpatchedGem = Struct.new(:gem, :advisory) do + alias_method :rubygem, :gem + end # The advisory database # @@ -30,15 +32,18 @@ class Scanner # # Initializes a scanner. # - # @param [String] root - # The path to the project root. + # @param [String, #read] path_io + # The path to a directory with a Gemfile.lock, or an IO representation of Gemfile.lock # - def initialize(root=Dir.pwd) - @root = File.expand_path(root) + def initialize(path_io=Dir.pwd) @database = Database.new - @lockfile = LockfileParser.new( - File.read(File.join(@root,'Gemfile.lock')) - ) + @lockfile = if path_io.respond_to?(:read) + @root = nil + LockfileParser.new(path_io.read) + else + @root = path_io + LockfileParser.new File.read(File.join(@root,'Gemfile.lock')) + end end #