Class: ExceptionsBegone::Formatter
- Inherits:
-
Object
- Object
- ExceptionsBegone::Formatter
- Defined in:
- lib/exceptions_begone/formatter.rb
Class Method Summary collapse
- .format_data(category, notification) ⇒ Object
- .format_exception_data(exception, controller, request) ⇒ Object
- .generate_identifier(controller, exception) ⇒ Object
- .serialize_data(data) ⇒ Object
- .to_json(attributes) ⇒ Object
Class Method Details
.format_data(category, notification) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/exceptions_begone/formatter.rb', line 4 def format_data(category, notification) notification.symbolize_keys! notification.merge!(:category => category) serialized_notification = serialize_data(notification) to_json(serialized_notification) end |
.format_exception_data(exception, controller, request) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/exceptions_begone/formatter.rb', line 11 def format_exception_data(exception, controller, request) { :identifier => generate_identifier(controller, exception), :payload => { :parameters => request.parameters, :url => request.url, :ip => request.ip, :request_environment => request.env, :session => request.session, :environment => ENV.to_hash, :backtrace => exception.backtrace } } end |
.generate_identifier(controller, exception) ⇒ Object
25 26 27 |
# File 'lib/exceptions_begone/formatter.rb', line 25 def generate_identifier(controller, exception) "#{controller.controller_name}##{controller.action_name} (#{exception.class}) #{exception.message.inspect}" end |
.serialize_data(data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/exceptions_begone/formatter.rb', line 29 def serialize_data(data) case data when String data when Hash data.inject({}) do |result, (key, value)| result.update(key => serialize_data(value)) end when Array data.map do |elem| serialize_data(elem) end else data.to_s end end |
.to_json(attributes) ⇒ Object
46 47 48 |
# File 'lib/exceptions_begone/formatter.rb', line 46 def to_json(attributes) ActiveSupport::JSON.encode(:notification => attributes) end |