Sha256: 4194dca6e8d77ca11b9a9200342d1dcaa6ca782e266b562d85c4e763adfc3d45

Contents?: true

Size: 910 Bytes

Versions: 8

Compression:

Stored size: 910 Bytes

Contents

require 'json'

module Hrw
  module Scanner
    #
    # Used to scan gem lock file
    #
    class Pipfile
      attr_reader :package_manager

      # Class constructor
      #
      # @param [String] root The path to the project root
      # @param [String] lockfile
      #   The name for the lock file, default is `Pipfile.lock`
      def initialize(root = Dir.pwd, lockfile = 'Pipfile.lock')
        @package_manager = 'pypi'
        @root = root
        @lockfile = lockfile
      end

      # Scan the lock file
      # @return [Hash] Dependencies
      def scan
        deps = []

        lock = JSON.parse(File.read(File.join(@root, @lockfile)))
        lock['default'].each_pair do |name, info|
          next if info['version'].nil?
          deps << {
            name: name,
            version: info['version'].delete_prefix('==')
          }
        end

        deps
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hrw-0.3.9 lib/hrw/scanner/pipfile.rb
hrw-0.3.8 lib/hrw/scanner/pipfile.rb
hrw-0.3.7 lib/hrw/scanner/pipfile.rb
hrw-0.3.6 lib/hrw/scanner/pipfile.rb
hrw-0.3.5 lib/hrw/scanner/pipfile.rb
hrw-0.3.4 lib/hrw/scanner/pipfile.rb
hrw-0.3.3 lib/hrw/scanner/pipfile.rb
hrw-0.3.2 lib/hrw/scanner/pipfile.rb