Class: Telebugs::Report
- Inherits:
-
Object
- Object
- Telebugs::Report
- Defined in:
- lib/telebugs/report.rb
Overview
Represents a piece of information that will be sent to Telebugs API to report an error.
Constant Summary collapse
- JSON_EXCEPTIONS =
The list of possible exceptions that might be raised when an object is converted to JSON
[ IOError, NotImplementedError, JSON::GeneratorError, Encoding::UndefinedConversionError ].freeze
- MAX_REPORT_SIZE =
The maxium size of the JSON data in bytes
64000
- DATA_MAX_SIZE =
The maximum size of hashes, arrays and strings in the report.
10000
- REPORTER =
{ library: {name: "telebugs", version: Telebugs::VERSION}.freeze, platform: {name: "Ruby", version: RUBY_VERSION}.freeze }.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#ignored ⇒ Object
Returns the value of attribute ignored.
Instance Method Summary collapse
-
#initialize(error) ⇒ Report
constructor
A new instance of Report.
-
#to_json(*_args) ⇒ Object
Converts the report to JSON.
Constructor Details
#initialize(error) ⇒ Report
Returns a new instance of Report.
30 31 32 33 34 35 36 37 38 |
# File 'lib/telebugs/report.rb', line 30 def initialize(error) @ignored = false @truncator = Truncator.new(DATA_MAX_SIZE) @data = { errors: errors_as_json(error), reporters: [REPORTER] } end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
27 28 29 |
# File 'lib/telebugs/report.rb', line 27 def data @data end |
#ignored ⇒ Object
Returns the value of attribute ignored.
28 29 30 |
# File 'lib/telebugs/report.rb', line 28 def ignored @ignored end |
Instance Method Details
#to_json(*_args) ⇒ Object
Converts the report to JSON. Calls to_json
on each object inside the reports’ data. Truncates report data, JSON representation of which is bigger than MAX_REPORT_SIZE.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/telebugs/report.rb', line 43 def to_json(*_args) loop do begin json = @data.to_json rescue *JSON_EXCEPTIONS # TODO: log the error else return json if json && json.bytesize <= MAX_REPORT_SIZE end break if truncate == 0 end end |