Class: Hrw::Scanner::Pipfile

Inherits:
Object
  • Object
show all
Defined in:
lib/hrw/scanner/pipfile.rb

Overview

Used to scan gem lock file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd, lockfile = 'Pipfile.lock') ⇒ Pipfile

Class constructor

Parameters:

  • root (String) (defaults to: Dir.pwd)

    The path to the project root

  • lockfile (String) (defaults to: 'Pipfile.lock')

    The name for the lock file, default is ‘Pipfile.lock`



16
17
18
19
20
# File 'lib/hrw/scanner/pipfile.rb', line 16

def initialize(root = Dir.pwd, lockfile = 'Pipfile.lock')
  @package_manager = 'pypi'
  @root = root
  @lockfile = lockfile
end

Instance Attribute Details

#package_managerObject (readonly)

Returns the value of attribute package_manager.



9
10
11
# File 'lib/hrw/scanner/pipfile.rb', line 9

def package_manager
  @package_manager
end

Instance Method Details

#scanHash

Scan the lock file

Returns:

  • (Hash)

    Dependencies



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hrw/scanner/pipfile.rb', line 24

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