Module: Datadog::CI::SourceCode::StaticDependencies

Defined in:
lib/datadog/ci/source_code/static_dependencies.rb

Class Method Summary collapse

Class Method Details

.fetch_static_dependencies(file) ⇒ Hash{String => Boolean}

Fetch static dependencies for a given file.

Parameters:

  • file (String, nil)

    The file path to look up

Returns:

  • (Hash{String => Boolean})

    Dependencies hash or empty hash



62
63
64
65
66
67
# File 'lib/datadog/ci/source_code/static_dependencies.rb', line 62

def self.fetch_static_dependencies(file)
  return {} unless @dependencies_map
  return {} if file.nil?

  @dependencies_map.fetch(file, {})
end

.populate!(root_path, ignored_path = nil) ⇒ Hash{String => Hash{String => Boolean}}

Populate the static dependencies map by scanning all live ISeqs.

Parameters:

  • root_path (String)

    Only process files under this path

  • ignored_path (String, nil) (defaults to: nil)

    Exclude files under this path

Returns:

  • (Hash{String => Hash{String => Boolean}})

    The dependencies map

Raises:

  • (ArgumentError)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/datadog/ci/source_code/static_dependencies.rb', line 46

def self.populate!(root_path, ignored_path = nil)
  raise ArgumentError, "root_path must be a String and not nil" if root_path.nil? || !root_path.is_a?(String)

  extractor = StaticDependenciesExtractor.new(root_path, ignored_path)

  ISeqCollector.collect.each do |iseq|
    extractor.extract(iseq)
  end

  @dependencies_map = extractor.dependencies_map
end