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.
151 152 153 154 155 156 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 151 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.
139 140 141 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 139 def dependencies_map @dependencies_map end |
#ignored_path ⇒ String? (readonly)
Returns Ignored path prefix for exclusion.
145 146 147 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 145 def ignored_path @ignored_path end |
#root_path ⇒ String (readonly)
Returns Root path prefix for filtering.
142 143 144 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 142 def root_path @root_path end |
Instance Method Details
#extract(iseq) ⇒ void
This method returns an undefined value.
Extract constant dependencies from an ISeq.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 162 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.
181 182 183 |
# File 'lib/datadog/ci/source_code/static_dependencies_extractor.rb', line 181 def reset @dependencies_map = {} end |