Class: Datadog::CI::SourceCode::StaticDependenciesExtractor::BytecodeScanner Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/source_code/static_dependencies_extractor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

BytecodeScanner scans Ruby bytecode instructions for constant references.

This class traverses the ISeq#to_a representation to find:

  • :getconstant instructions - simple constant references

  • :opt_getconstant_path instructions - optimized qualified constant paths

API:

  • private

Instance Method Summary collapse

Instance Method Details

#build_constant_path(symbol_array) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a qualified constant name from an array of symbols. e.g., [:Foo, :Bar, :Baz] -> “Foo::Bar::Baz”

Parameters:

  • Array of constant name symbols

Returns:

  • The qualified constant path string

API:

  • private



51
52
53
54
55
56
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 51

def build_constant_path(symbol_array)
  symbol_array
    .select { |part| part.is_a?(Symbol) }
    .map(&:to_s)
    .join("::")
end

#scan(body) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Scan an ISeq body for constant references.

Parameters:

  • The ISeq body array (last element of ISeq#to_a)

Returns:

  • Array of constant name strings found in the bytecode

API:

  • private



38
39
40
41
42
43
44
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 38

def scan(body)
  return [] unless body.is_a?(Array)

  constants = []
  scan_value(body, constants)
  constants
end