Class: Errordite::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/errordite/serializer.rb

Constant Summary collapse

SPECIAL_CONTEXT_ATTRIBUTES =
['MachineName', 'Url', 'UserAgent', 'Version']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, context = {}) ⇒ Serializer

Returns a new instance of Serializer.



9
10
11
12
# File 'lib/errordite/serializer.rb', line 9

def initialize(exception, context = {})
  @exception = exception
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/errordite/serializer.rb', line 7

def context
  @context
end

#exceptionObject (readonly)

Returns the value of attribute exception.



7
8
9
# File 'lib/errordite/serializer.rb', line 7

def exception
  @exception
end

Instance Method Details

#as_jsonObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/errordite/serializer.rb', line 14

def as_json
  special_attributes.merge(
    "Token" => Errordite.api_token,
    "TimestampUtc" => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
    "ExceptionInfo" => {
      "Source" => source,
      "Message" => exception.message,
      "MethodName" => method_name,
      "ExceptionType" => exception.class.name,
      "StackTrace" => stack_trace,
      "Data" => exception_data
    }
  )
end

#to_jsonObject



29
30
31
# File 'lib/errordite/serializer.rb', line 29

def to_json
  JSON.dump(as_json)
end