Class: RShade::Formatter::Stack::Json

Inherits:
Object
  • Object
show all
Defined in:
lib/rshade/formatter/stack/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath:, pretty: false) ⇒ Json

Returns a new instance of Json.



9
10
11
12
# File 'lib/rshade/formatter/stack/json.rb', line 9

def initialize(filepath:, pretty: false)
  @filepath = filepath
  @pretty = pretty
end

Instance Attribute Details

#filepathObject (readonly)

Returns the value of attribute filepath.



7
8
9
# File 'lib/rshade/formatter/stack/json.rb', line 7

def filepath
  @filepath
end

#prettyObject (readonly)

Returns the value of attribute pretty.



7
8
9
# File 'lib/rshade/formatter/stack/json.rb', line 7

def pretty
  @pretty
end

#variable_serializerObject (readonly)

Returns the value of attribute variable_serializer.



7
8
9
# File 'lib/rshade/formatter/stack/json.rb', line 7

def variable_serializer
  @variable_serializer
end

Instance Method Details

#call(stack_frames, variable_serializer: nil) ⇒ Object

Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rshade/formatter/stack/json.rb', line 15

def call(stack_frames, variable_serializer: nil)
  payload = stack_frames.map.with_index do |frame, idx|
    serialize(idx, frame, variable_serializer)
  end

  File.open(filepath, 'a+') do |file|
    record = {
      time: Time.now.getutc,
      thread_id: Thread.current,
      thread_list: Thread.list,
      frames: payload
    }
    file.puts(convert_to_json(record, pretty))
  end
end