Sha256: 66b84f6f479fe19b1f91b825957d100121fb738d8d35eb7b5825c2b447da49d8

Contents?: true

Size: 1.08 KB

Versions: 11

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Spandx
  module Python
    module Parsers
      class PipfileLock < ::Spandx::Core::Parser
        def match?(path)
          path.basename.fnmatch?('Pipfile*.lock')
        end

        def parse(lockfile)
          results = []
          dependencies_from(lockfile) do |dependency|
            results << dependency
          end
          results
        end

        private

        def dependencies_from(lockfile)
          json = Oj.load(lockfile.read)
          each_dependency(json) do |name, version|
            yield ::Spandx::Core::Dependency.new(
              path: lockfile,
              name: name,
              version: version,
              meta: json
            )
          end
        end

        def each_dependency(json, groups: %w[default develop])
          groups.each do |group|
            json[group].each do |name, value|
              yield name, canonicalize(value['version'])
            end
          end
        end

        def canonicalize(version)
          version.gsub(/==/, '')
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.18.2 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.18.1 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.18.0 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.17.0 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.16.1 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.16.0 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.15.1 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.15.0 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.14.0 lib/spandx/python/parsers/pipfile_lock.rb
spandx-0.13.5 lib/spandx/python/parsers/pipfile_lock.rb