Class: Google::Cloud::Debugger::Breakpoint::Variable
- Inherits:
-
Object
- Object
- Google::Cloud::Debugger::Breakpoint::Variable
- Defined in:
- lib/google/cloud/debugger/breakpoint/variable.rb
Overview
Variable
Represents a variable or an argument possibly of a compound object type. Note how the following variables are represented:
A simple Variable:
x = 5
# Captured variable:
# { name: "x", value: "5", type: "Integer" }
A Compound Variable:
class T
attr_accessor :m1, :m2
...
end
v = T.new(1, "2")
# Captured variable:
# {
# name: "v",
# type: "T",
# members: [
# { name: "@m1", value: "1", type: "Integer" },
# { name: "@m2", value: "2", type: "String" }
# ]
# }
A Hash object:
hash = { a: 1, b: :two }
# Captured variable:
# {
# name: "hash",
# type: "Hash",
# members: [
# { name: "a", value: "1", type: "Integer" },
# { name: "b", value: ":2", type: "Symbol" }
# ]
# }
An Array object:
ary = [1, nil]
# Captured variable:
# {
# name: "ary",
# type: "Array",
# members: [
# { name: "[0]", value: "1", type: "Integer" },
# { name: "[1]", value: "nil", type: "NilClass" }
# ]
# }
Constant Summary collapse
- MAX_DEPTH =
Max depth to convert on compound variables
3
- MAX_MEMBERS =
Max number of member variables to evaluate in compound variables
1000
- MAX_STRING_LENGTH =
Max length on variable inspect results. Truncate extra and replace with ellipsis.
500
Class Method Summary collapse
-
.from_rb_var(source, name: nil, depth: MAX_DEPTH, var_table: nil, limit: nil) ⇒ Google::Cloud::Debugger::Breakpoint::Variable
Convert a Ruby variable into a Google::Cloud::Debugger::Breakpoint::Variable object.
Instance Method Summary collapse
-
#payload_size ⇒ Integer
Calculate the bytesize of all the attributes and that of the member variables.
-
#set_error_state(message, refers_to: StatusMessage::VARIABLE_VALUE) ⇒ Object
Set this variable to an error state by setting the status field.
-
#to_grpc ⇒ Object
Exports the Variable to a Google::Devtools::Clouddebugger::V2::Variable object.
-
#total_size ⇒ Integer
Calculate the total bytesize of all the attributes and that of the member variables, plus references into other variables in the variable table.
Class Method Details
.from_rb_var(source, name: nil, depth: MAX_DEPTH, var_table: nil, limit: nil) ⇒ Google::Cloud::Debugger::Breakpoint::Variable
Convert a Ruby variable into a Google::Cloud::Debugger::Breakpoint::Variable object. If a variable table is provided, it will store all the subsequently created compound variables into the variable table for sharing.
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 236 def self.from_rb_var source, name: nil, depth: MAX_DEPTH, var_table: nil, limit: nil return source if source.is_a? Variable if limit && limit < MIN_REQUIRED_SIZE return buffer_full_variable var_table end # If source is a non-empty Array or Hash, or source has instance # variables, evaluate source as a compound variable. if compound_var?(source) && depth > 0 from_compound_var source, name: name, depth: depth, var_table: var_table, limit: limit else from_primitive_var source, name: name, limit: limit end rescue new.tap do |var| var.name = name.to_s if name var.set_error_state FAIL_CONVERSION_MSG var.source_var = source end end |
Instance Method Details
#payload_size ⇒ Integer
Calculate the bytesize of all the attributes and that of the member variables.
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 510 def payload_size unless @payload_size @payload_size = name.to_s.bytesize + type.to_s.bytesize + value.to_s.bytesize unless members.nil? @payload_size = members.inject(@payload_size) do |sum, member| sum + member.payload_size end end end @payload_size end |
#set_error_state(message, refers_to: StatusMessage::VARIABLE_VALUE) ⇒ Object
Set this variable to an error state by setting the status field
475 476 477 478 479 480 481 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 475 def set_error_state , refers_to: StatusMessage::VARIABLE_VALUE @status = StatusMessage.new.tap do |s| s.is_error = true s.refers_to = refers_to s.description = end end |
#to_grpc ⇒ Object
Exports the Variable to a Google::Devtools::Clouddebugger::V2::Variable object.
461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 461 def to_grpc return nil if empty? Google::Devtools::Clouddebugger::V2::Variable.new( name: name.to_s, value: value.to_s, type: type.to_s, var_table_index: var_table_index_to_grpc, members: members_to_grpc || [], status: status_to_grpc ) end |
#total_size ⇒ Integer
Calculate the total bytesize of all the attributes and that of the member variables, plus references into other variables in the variable table.
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
# File 'lib/google/cloud/debugger/breakpoint/variable.rb', line 489 def total_size unless @total_size vars = [self, *(unique_members || [])] @total_size = vars.inject(payload_size) do |sum, var| if var.var_table && var.var_table_index sum + var.var_table[var.var_table_index].total_size else sum end end end @total_size end |