Class: Datadog::SymbolDatabase::Symbol Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/symbol_database/symbol.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 symbol (variable, parameter, field, constant) within a scope.

Symbols are the actual identifiers extracted from Ruby code:

  • Instance variables (@var) - FIELD type
  • Class variables (@@var) - STATIC_FIELD type
  • Constants (CONST) - STATIC_FIELD type
  • Method parameters (arg) - ARG type
  • Local variables (var) - LOCAL type (not yet implemented)

Created by: Extractor (during class/method introspection) Contained in: Scope objects (symbols array) Serialized to: JSON via to_h/to_json

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol_type:, name:, line:, type: nil, language_specifics: nil) ⇒ Symbol

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 Symbol

Parameters:

  • symbol_type (String) —

    Type: FIELD, STATIC_FIELD, ARG, LOCAL

  • name (String) —

    Symbol name (variable name, parameter name)

  • line (Integer) —

    Line number (UNKNOWN_MIN_LINE for entire scope, UNKNOWN_MAX_LINE for method-level only)

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

    Type annotation (optional, Ruby is dynamic)

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

    Symbol-specific metadata



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/datadog/symbol_database/symbol.rb', line 30

def initialize(
  symbol_type:,
  name:,
  line:,
  type: nil,
  language_specifics: nil
)
  @symbol_type = symbol_type
  @name = name
  @line = line
  @type = type
  @language_specifics = language_specifics
end

Instance Attribute Details

#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.



22
23
24
# File 'lib/datadog/symbol_database/symbol.rb', line 22

def language_specifics
  @language_specifics
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.



22
23
24
# File 'lib/datadog/symbol_database/symbol.rb', line 22

def line
  @line
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.



22
23
24
# File 'lib/datadog/symbol_database/symbol.rb', line 22

def name
  @name
end

#symbol_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.



22
23
24
# File 'lib/datadog/symbol_database/symbol.rb', line 22

def symbol_type
  @symbol_type
end

#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.



22
23
24
# File 'lib/datadog/symbol_database/symbol.rb', line 22

def type
  @type
end

Instance Method Details

#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 symbol to Hash for JSON serialization. The type key is always present per the symdb JSON schema — emit nil when the type cannot be determined (the common case in Ruby since parameters and instance variables carry no declared type). language_specifics is omitted when nil to reduce payload size.

Returns:

  • (Hash) —

    Symbol as hash with symbol keys



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/symbol_database/symbol.rb', line 50

def to_h
  # @type var h: Hash[::Symbol, untyped]
  h = {
    symbol_type: symbol_type,
    name: name,
    line: line,
    type: type,
  }
  h[:language_specifics] = language_specifics if language_specifics
  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 symbol to JSON.

Returns:

  • (String) —

    JSON string representation



64
65
66
# File 'lib/datadog/symbol_database/symbol.rb', line 64

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