Class: Spandx::Terraform::Parsers::LockFile
- Inherits:
-
Core::Parser
- Object
- Core::Parser
- Spandx::Terraform::Parsers::LockFile
- Defined in:
- lib/spandx/terraform/parsers/lock_file.rb
Constant Summary
Constants inherited from Core::Parser
Instance Method Summary collapse
-
#initialize ⇒ LockFile
constructor
A new instance of LockFile.
- #match?(pathname) ⇒ Boolean
- #parse(path) ⇒ Object
Methods inherited from Core::Parser
Methods included from Core::Registerable
#all, #each, #inherited, #registry
Constructor Details
#initialize ⇒ LockFile
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
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 |