Class: CrashHook::Payload

Inherits:
Object
  • Object
show all
Includes:
Serializer
Defined in:
lib/crash_hook/payload.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Serializer

#clean_non_serializable_data, #serializable?

Constructor Details

#initialize(exception, env, extra_params = {}) ⇒ Payload

Initialize a new CrashHook::Payload object

exception    => Exception object instance
env          => Environment hash
extra_params => Additional parameters


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/crash_hook/payload.rb', line 19

def initialize(exception, env, extra_params={})
  @exception = {
    :class_name => exception.class.to_s,
    :message    => exception.message,
    :backtrace  => exception.backtrace,
    :timestamp  => Time.now
  }
  
  @environment  = clean_non_serializable_data(env)
  @version      = CrashHook::VERSION
  @framework    = 'rack'
  @framework    = 'rails'   if defined?(Rails)
  @framework    = 'sinatra' if defined?(Sinatra)
  @extra_params = extra_params.kind_of?(Hash) ? extra_params : {}
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



9
10
11
# File 'lib/crash_hook/payload.rb', line 9

def environment
  @environment
end

#exceptionObject (readonly)

Returns the value of attribute exception.



8
9
10
# File 'lib/crash_hook/payload.rb', line 8

def exception
  @exception
end

#extra_paramsObject (readonly)

Returns the value of attribute extra_params.



12
13
14
# File 'lib/crash_hook/payload.rb', line 12

def extra_params
  @extra_params
end

#frameworkObject (readonly)

Returns the value of attribute framework.



10
11
12
# File 'lib/crash_hook/payload.rb', line 10

def framework
  @framework
end

#versionObject (readonly)

Returns the value of attribute version.



11
12
13
# File 'lib/crash_hook/payload.rb', line 11

def version
  @version
end

Instance Method Details

#to_hashObject

Returns HASH representation of payload



36
37
38
39
40
41
42
43
# File 'lib/crash_hook/payload.rb', line 36

def to_hash
  {
    :exception   => @exception,
    :environment => @environment,
    :version     => @version,
    :framework   => @framework
  }
end

#to_jsonObject

Returns JSON representation of payload



47
48
49
50
51
# File 'lib/crash_hook/payload.rb', line 47

def to_json
  @extra_params.delete(:crash)
  @extra_params.delete('crash')
  MultiJson.encode({:crash => self.to_hash}.merge(@extra_params))
end

#to_xmlObject

Returns XML representation of payload



61
62
63
# File 'lib/crash_hook/payload.rb', line 61

def to_xml
  # Not Implemented Yet
end

#to_yamlObject

Returns YAML representation of payload



55
56
57
# File 'lib/crash_hook/payload.rb', line 55

def to_yaml
  YAML.dump({:crash => self.to_hash})
end