Sha256: b2e9fe00e106ad9bfd3c9972c6c016189de22b7f771cdb62f0b9fbeb7dff38c4

Contents?: true

Size: 755 Bytes

Versions: 2

Compression:

Stored size: 755 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class GemfileLock < Base
      def self.matches?(filename)
        filename.match?(/Gemfile.*\.lock/)
      end

      def parse(lockfile)
        report = Report.new
        dependencies_from(lockfile) do |dependency|
          spec = dependency.to_spec
          report.add(
            name: dependency.name,
            version: spec.version.to_s,
            licenses: [catalogue[spec.license]]
          )
        end
        report
      end

      private

      def dependencies_from(lockfile)
        ::Bundler::LockfileParser
          .new(IO.read(lockfile))
          .dependencies.each do |_key, dependency|
          yield dependency
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spandx-0.1.3 lib/spandx/parsers/gemfile_lock.rb
spandx-0.1.2 lib/spandx/parsers/gemfile_lock.rb