Class: Spandx::Terraform::Parsers::LockFile

Inherits:
Core::Parser show all
Defined in:
lib/spandx/terraform/parsers/lock_file.rb

Constant Summary

Constants inherited from Core::Parser

Core::Parser::UNKNOWN

Instance Method Summary collapse

Methods inherited from Core::Parser

for, parse

Methods included from Core::Registerable

#all, #each, #inherited, #registry

Constructor Details

#initializeLockFile

Returns a new instance of LockFile.



7
8
9
10
# File 'lib/spandx/terraform/parsers/lock_file.rb', line 7

def initialize
  @parser = Hcl2::Parser.new
  super()
end

Instance Method Details

#match?(pathname) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/spandx/terraform/parsers/lock_file.rb', line 12

def match?(pathname)
  basename = pathname.basename
  basename.fnmatch?('.terraform.lock.hcl')
end

#parse(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/spandx/terraform/parsers/lock_file.rb', line 17

def parse(path)
  tree = @parser.parse(path.read)
  tree[:blocks].map do |block|
    version_arg = version_arg_from(block)
    ::Spandx::Core::Dependency.new(
      name: block[:name].to_s,
      version: version_arg[:value]&.to_s,
      path: path
    )
  end
end