Class: Datadog::CI::SourceCode::StaticDependenciesExtractor
- Inherits:
-
Object
- Object
- Datadog::CI::SourceCode::StaticDependenciesExtractor
- Defined in:
- lib/datadog/ci/source_code/static_dependencies_extractor.rb
Overview
StaticDependenciesExtractor extracts static constant dependencies from Ruby bytecode.
For each ISeq (compiled Ruby code), it:
-
Extracts the source file path
-
Filters by root_path and ignored_path
-
Scans bytecode for constant references
-
Resolves constants to their source file locations
-
Filters dependency paths by root_path and ignored_path
Defined Under Namespace
Classes: BytecodeScanner
Instance Attribute Summary collapse
-
#dependencies_map ⇒ Hash{String => Hash{String => Boolean}}
readonly
Map of source file to dependencies.
-
#ignored_path ⇒ String?
readonly
Ignored path prefix for exclusion.
-
#root_path ⇒ String
readonly
Root path prefix for filtering.
Instance Method Summary collapse
-
#extract(iseq) ⇒ void
Extract constant dependencies from an ISeq.
-
#initialize(root_path, ignored_path = nil) ⇒ StaticDependenciesExtractor
constructor
Initialize a new StaticDependenciesExtractor.
-
#reset ⇒ void
Reset the dependencies map.
Constructor Details
#initialize(root_path, ignored_path = nil) ⇒ StaticDependenciesExtractor
Initialize a new StaticDependenciesExtractor.
150 151 152 153 154 155 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 150 def initialize(root_path, ignored_path = nil) @root_path = root_path @ignored_path = ignored_path @dependencies_map = {} @bytecode_scanner = BytecodeScanner.new end |
Instance Attribute Details
#dependencies_map ⇒ Hash{String => Hash{String => Boolean}} (readonly)
Returns Map of source file to dependencies.
138 139 140 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 138 def dependencies_map @dependencies_map end |
#ignored_path ⇒ String? (readonly)
Returns Ignored path prefix for exclusion.
144 145 146 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 144 def ignored_path @ignored_path end |
#root_path ⇒ String (readonly)
Returns Root path prefix for filtering.
141 142 143 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 141 def root_path @root_path end |
Instance Method Details
#extract(iseq) ⇒ void
This method returns an undefined value.
Extract constant dependencies from an ISeq.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 161 def extract(iseq) path = extract_absolute_path(iseq) return if path.nil? return unless PathFilter.included?(path, root_path, ignored_path) body = extract_body(iseq) return if body.nil? deps = get_or_create_deps(path) constant_names = @bytecode_scanner.scan(body) constant_names.each do |const_name| resolve_and_store_dependency(const_name, deps) end end |
#reset ⇒ void
This method returns an undefined value.
Reset the dependencies map.
180 181 182 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 180 def reset @dependencies_map = {} end |