Class: Aws::Xray::Cause
- Inherits:
-
Object
- Object
- Aws::Xray::Cause
- Defined in:
- lib/aws/xray/cause.rb
Constant Summary collapse
- MAX_BACKTRACE_SIZE =
10
Instance Method Summary collapse
- #build_stack(stack, dir) ⇒ Object
-
#initialize(stack: [], message: nil, type: nil) ⇒ Cause
constructor
A new instance of Cause.
- #to_h(remote: false) ⇒ Object
Constructor Details
#initialize(stack: [], message: nil, type: nil) ⇒ Cause
Returns a new instance of Cause.
6 7 8 9 10 11 12 |
# File 'lib/aws/xray/cause.rb', line 6 def initialize(stack: [], message: nil, type: nil) @id = SecureRandom.hex(8) @working_directory = (Dir.pwd + '/') rescue '/' @stack = stack @message = @type = type end |
Instance Method Details
#build_stack(stack, dir) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/aws/xray/cause.rb', line 32 def build_stack(stack, dir) truncated = [stack.size - MAX_BACKTRACE_SIZE, 0].max stack = stack[0..MAX_BACKTRACE_SIZE - 1].map do |s| file, line, method_name = s.split(':') { path: file.sub(dir, ''), line: line, label: method_name, } end return truncated, stack end |
#to_h(remote: false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/aws/xray/cause.rb', line 14 def to_h(remote: false) truncated, stack = build_stack(@stack, @working_directory) { working_directory: @working_directory, paths: [], exceptions: [ { id: @id, message: @message, type: @type, remote: remote, truncated: truncated, stack: stack, }, ], } end |