Class: ExceptionNo
- Inherits:
-
Object
- Object
- ExceptionNo
- Defined in:
- lib/exception_no.rb
Defined Under Namespace
Classes: Middleware
Constant Summary collapse
- VERSION =
"0.0.3"
- TEMPLATE =
(<<-'EMAIL').gsub(/^ {2}/, '') From: <%= @config[:from_alias] %> <<%= @config[:from] %>> To: <<%= @config[:to] %>> Subject: <%= exception.class %>: <%= exception.message.split.join(" ") %> <%= options[:body] %> <%= "~" * 80 %> A <%= exception.class.to_s %> occured: <%= exception.to_s %> <%= exception.backtrace.select { |line| @backtrace_filter.call(line) }.join("\n") if exception.backtrace %> EMAIL
Instance Attribute Summary collapse
-
#backtrace_filter ⇒ Object
Returns the value of attribute backtrace_filter.
-
#deliver ⇒ Object
Returns the value of attribute deliver.
Instance Method Summary collapse
- #_notify(exception, options = {}) ⇒ Object
-
#initialize(config = {}) ⇒ ExceptionNo
constructor
A new instance of ExceptionNo.
- #notify(exception, options = {}) ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ ExceptionNo
Returns a new instance of ExceptionNo.
10 11 12 13 14 15 16 |
# File 'lib/exception_no.rb', line 10 def initialize(config = {}) @config = config @template = ERB.new(TEMPLATE) @deliver = true @backtrace_filter = -> line { true } end |
Instance Attribute Details
#backtrace_filter ⇒ Object
Returns the value of attribute backtrace_filter.
7 8 9 |
# File 'lib/exception_no.rb', line 7 def backtrace_filter @backtrace_filter end |
#deliver ⇒ Object
Returns the value of attribute deliver.
8 9 10 |
# File 'lib/exception_no.rb', line 8 def deliver @deliver end |
Instance Method Details
#_notify(exception, options = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/exception_no.rb', line 18 def _notify(exception, = {}) body = @template.result(binding) Net::SMTP.start(@config.fetch(:host), @config.fetch(:port, 25)) do |smtp| smtp.(body, @config.fetch(:from), @config.fetch(:to)) end end |
#notify(exception, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/exception_no.rb', line 26 def notify(exception, = {}) return unless @deliver begin _notify(exception, ) rescue => notification_error $stderr.write("*** FAILED SENDING ERROR NOTIFICATION\n") $stderr.write("*** #{notification_error.class}: #{notification_error}\n") $stderr.write("*** #{exception.class}: #{exception.}\n") exception.backtrace.each do |line| $stderr.write("*** #{line}\n") end end end |