Class: Chatterbox::ExceptionNotification::Presenter
- Inherits:
-
Object
- Object
- Chatterbox::ExceptionNotification::Presenter
- Defined in:
- lib/chatterbox/exception_notification/presenter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #error_details ⇒ Object
-
#initialize(options = {}) ⇒ Presenter
constructor
A new instance of Presenter.
- #render_array(object) ⇒ Object
- #render_body ⇒ Object
-
#render_hash(hsh) ⇒ Object
renders hashes with keys in alpha-sorted order.
- #render_obj(object) ⇒ Object
- #render_object(object) ⇒ Object
- #render_section(key, processed_keys = []) ⇒ Object
- #render_sections(keys, already_processed) ⇒ Object
- #summary ⇒ Object
- #to_message ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Presenter
Returns a new instance of Presenter.
12 13 14 15 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 12 def initialize( = {}) @options = @config = [:config] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 6 def @options end |
Class Method Details
.render(options) ⇒ Object
8 9 10 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 8 def self.render() new(). end |
Instance Method Details
#error_details ⇒ Object
27 28 29 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 27 def error_details [:error_message, :request, :backtrace, :environment, :ruby_info, :rails_info, :chatterbox_info] end |
#render_array(object) ⇒ Object
65 66 67 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 65 def render_array(object) render_object(object.join("\n")) end |
#render_body ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 31 def render_body processed_keys = [] extra_sections = .keys - error_details body = render_sections(extra_sections, processed_keys) body << render_sections(error_details, processed_keys) body end |
#render_hash(hsh) ⇒ Object
renders hashes with keys in alpha-sorted order
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 74 def render_hash(hsh) str = "" indiff_hsh = hsh.with_indifferent_access indiff_hsh.keys.sort.each do |key| str << "#{key}: " value = indiff_hsh[key] PP::pp(value, str) end str end |
#render_obj(object) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 57 def render_obj(object) case object when Hash then render_hash(object) when Array then render_array(object) else render_object(object) end end |
#render_object(object) ⇒ Object
69 70 71 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 69 def render_object(object) "#{object}\n" end |
#render_section(key, processed_keys = []) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 47 def render_section(key, processed_keys = []) processed_keys << key return nil unless .key?(key) output = "#{key.to_s.titleize}\n" output << "----------\n" output << render_obj([key]) output << "\n" output end |
#render_sections(keys, already_processed) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 39 def render_sections(keys, already_processed) keys.inject(String.new) do |str, key| output = render_section(key, already_processed) str << output if output str end end |
#summary ⇒ Object
17 18 19 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 17 def summary .delete(:summary) end |
#to_message ⇒ Object
21 22 23 24 25 |
# File 'lib/chatterbox/exception_notification/presenter.rb', line 21 def { :summary => summary, :body => render_body, :config => @config } end |