Class: Datadog::SymbolDatabase::Scope Private
- Inherits:
-
Object
- Object
- Datadog::SymbolDatabase::Scope
- Defined in:
- lib/datadog/symbol_database/scope.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.
Represents a scope in the hierarchical symbol structure (FILE → MODULE/CLASS → METHOD).
Scopes form a tree structure representing Ruby code organization. Each scope contains:
- Metadata: name, source file, line range, scope type (MODULE/CLASS/METHOD/etc.)
- Symbols: Variables, constants, parameters defined in this scope
- Nested scopes: Child scopes (e.g., methods within a class)
Created by: Extractor (during symbol extraction) Used by: ScopeBatcher (batching), ServiceVersion (wrapping for upload) Serialized to: JSON via to_h/to_json for upload to agent
Instance Attribute Summary collapse
- #end_line ⇒ Object readonly private
- #language_specifics ⇒ Object readonly private
- #name ⇒ Object readonly private
- #scope_type ⇒ Object readonly private
- #scopes ⇒ Object readonly private
- #source_file ⇒ Object readonly private
- #start_line ⇒ Object readonly private
- #symbols ⇒ Object readonly private
- #targetable_lines ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(scope_type:, name: nil, source_file: nil, start_line: nil, end_line: nil, targetable_lines: nil, language_specifics: nil, symbols: nil, scopes: nil) ⇒ Scope
constructor
private
Initialize a new Scope.
-
#targetable_lines? ⇒ Boolean
private
True when targetable_lines is non-nil and non-empty.
-
#to_h ⇒ Hash
private
Convert scope to Hash for JSON serialization.
-
#to_json(_state = nil) ⇒ String
private
Serialize scope to JSON.
Constructor Details
#initialize(scope_type:, name: nil, source_file: nil, start_line: nil, end_line: nil, targetable_lines: nil, language_specifics: nil, symbols: nil, scopes: nil) ⇒ Scope
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.
Initialize a new Scope
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/datadog/symbol_database/scope.rb', line 42 def initialize( scope_type:, name: nil, source_file: nil, start_line: nil, end_line: nil, targetable_lines: nil, language_specifics: nil, symbols: nil, scopes: nil ) @scope_type = scope_type @name = name @source_file = source_file @start_line = start_line @end_line = end_line @targetable_lines = targetable_lines @language_specifics = language_specifics || {} @symbols = symbols || [] @scopes = scopes || [] end |
Instance Attribute Details
#end_line ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def end_line @end_line end |
#language_specifics ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def language_specifics @language_specifics end |
#name ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def name @name end |
#scope_type ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def scope_type @scope_type end |
#scopes ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def scopes @scopes end |
#source_file ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def source_file @source_file end |
#start_line ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def start_line @start_line end |
#symbols ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def symbols @symbols end |
#targetable_lines ⇒ Object (readonly)
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.
20 21 22 |
# File 'lib/datadog/symbol_database/scope.rb', line 20 def targetable_lines @targetable_lines end |
Instance Method Details
#targetable_lines? ⇒ Boolean
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.
Returns true when targetable_lines is non-nil and non-empty.
65 66 67 |
# File 'lib/datadog/symbol_database/scope.rb', line 65 def targetable_lines? !targetable_lines.nil? && !targetable_lines.empty? end |
#to_h ⇒ Hash
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.
Convert scope to Hash for JSON serialization. Removes nil values to reduce payload size.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/datadog/symbol_database/scope.rb', line 72 def to_h h = { scope_type: scope_type, name: name, source_file: source_file, start_line: start_line, end_line: end_line, language_specifics: language_specifics.empty? ? nil : language_specifics, symbols: symbols.empty? ? nil : symbols.map(&:to_h), scopes: scopes.empty? ? nil : scopes.map(&:to_h), } h.compact! # Targetable lines only on METHOD scopes (per spec — not on CLASS/MODULE/FILE). # Always emit has_injectible_lines (even when false) on METHOD scopes. # Wire format keeps the historical spelling +injectible+; Ruby identifier # is +targetable_lines+. if scope_type == "METHOD" h[:has_injectible_lines] = targetable_lines? # steep:ignore ArgumentTypeMismatch h[:injectible_lines] = targetable_lines if targetable_lines && !targetable_lines.empty? end h end |
#to_json(_state = nil) ⇒ 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.
Serialize scope to JSON.
97 98 99 |
# File 'lib/datadog/symbol_database/scope.rb', line 97 def to_json(_state = nil) JSON.generate(to_h) end |