Sha256: 57e0e9a1202b6b7193ae8414688df13f92ea23c3d49b40d848833aed1d6153e0

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class GemfileLock < Base
      STRIP_BUNDLED_WITH = /^BUNDLED WITH$(\r?\n)   (?<major>\d+)\.\d+\.\d+/m.freeze

      def self.matches?(filename)
        filename.match?(/Gemfile.*\.lock/) ||
          filename.match?(/gems.*\.lock/)
      end

      def parse(lockfile)
        content = IO.read(lockfile)
        dependencies_from(content).map do |specification|
          Dependency.new(
            name: specification.name,
            version: specification.version.to_s,
            licenses: licenses_for(specification)
          )
        end
      end

      private

      def dependencies_from(content)
        ::Bundler::LockfileParser
          .new(content.sub(STRIP_BUNDLED_WITH, ''))
          .specs
      end

      def licenses_for(specification)
        rubygems
          .licenses_for(specification.name, specification.version.to_s)
          .map { |x| catalogue[x] }
      end

      def rubygems
        @rubygems ||= Gateways::Rubygems.new
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spandx-0.5.0 lib/spandx/parsers/gemfile_lock.rb
spandx-0.4.1 lib/spandx/parsers/gemfile_lock.rb
spandx-0.4.0 lib/spandx/parsers/gemfile_lock.rb
spandx-0.3.0 lib/spandx/parsers/gemfile_lock.rb
spandx-0.2.0 lib/spandx/parsers/gemfile_lock.rb
spandx-0.1.7 lib/spandx/parsers/gemfile_lock.rb
spandx-0.1.6 lib/spandx/parsers/gemfile_lock.rb
spandx-0.1.5 lib/spandx/parsers/gemfile_lock.rb
spandx-0.1.4 lib/spandx/parsers/gemfile_lock.rb