Class: Datadog::SymbolDatabase::Scope Private

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Parameters:

  • scope_type (String) —

    Type of scope (FILE, MODULE, CLASS, METHOD)

  • name (String, nil) (defaults to: nil) —

    Name of the scope (class name, method name, etc.)

  • source_file (String, nil) (defaults to: nil) —

    Path to source file

  • start_line (Integer, nil) (defaults to: nil) —

    Starting line number (UNKNOWN_MIN_LINE for unknown)

  • end_line (Integer, nil) (defaults to: nil) —

    Ending line number (UNKNOWN_MAX_LINE for entire file)

  • targetable_lines (Array<Hash>, nil) (defaults to: nil) —

    Ranges of executable lines [end:]

  • language_specifics (Hash, nil) (defaults to: nil) —

    Ruby-specific metadata

  • symbols (Array<Symbol>, nil) (defaults to: nil) —

    Symbols defined in this scope

  • scopes (Array<Scope>, nil) (defaults to: nil) —

    Nested child scopes



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.

Returns:

  • (Boolean) —

    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.

Returns:

  • (Hash) —

    Scope as hash with symbol keys



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.

Returns:

  • (String) —

    JSON string representation



97
98
99
# File 'lib/datadog/symbol_database/scope.rb', line 97

def to_json(_state = nil)
  JSON.generate(to_h)
end