Class: Exceptron::Presenter
- Inherits:
-
Object
- Object
- Exceptron::Presenter
- Defined in:
- lib/exceptron/exception.rb
Class Attribute Summary collapse
-
.statuses ⇒ Object
Returns the value of attribute statuses.
Instance Attribute Summary collapse
-
#wrapped_exception ⇒ Object
readonly
Returns the value of attribute wrapped_exception.
Instance Method Summary collapse
- #actions ⇒ Object
-
#initialize(exception) ⇒ Presenter
constructor
A new instance of Presenter.
- #original_exception ⇒ Object
- #status_code ⇒ Object
- #status_message ⇒ Object
- #to_json(options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
Constructor Details
#initialize(exception) ⇒ Presenter
Returns a new instance of Presenter.
2 3 4 |
# File 'lib/exceptron/exception.rb', line 2 def initialize(exception) @wrapped_exception = exception end |
Class Attribute Details
.statuses ⇒ Object
Returns the value of attribute statuses.
8 9 10 |
# File 'lib/exceptron/exception.rb', line 8 def statuses @statuses end |
Instance Attribute Details
#wrapped_exception ⇒ Object (readonly)
Returns the value of attribute wrapped_exception.
5 6 7 |
# File 'lib/exceptron/exception.rb', line 5 def wrapped_exception @wrapped_exception end |
Instance Method Details
#actions ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/exceptron/exception.rb', line 31 def actions original_exception.class.ancestors.map do |klass| status_code = self.class.statuses[klass] status = Rack::Utils::HTTP_STATUS_CODES[status_code] status.to_s.downcase.gsub(/\s|-/, '_') if status end.compact end |
#original_exception ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/exceptron/exception.rb', line 39 def original_exception if wrapped_exception.respond_to?(:original_exception) wrapped_exception.original_exception else wrapped_exception end end |
#status_code ⇒ Object
20 21 22 23 24 |
# File 'lib/exceptron/exception.rb', line 20 def status_code statuses = self.class.statuses registered_exception = original_exception.class.ancestors.find { |klass| statuses.key? klass } statuses[registered_exception] end |
#status_message ⇒ Object
26 27 28 29 |
# File 'lib/exceptron/exception.rb', line 26 def status = Rack::Utils::HTTP_STATUS_CODES[status_code] status.to_s if status end |
#to_json(options = {}) ⇒ Object
16 17 18 |
# File 'lib/exceptron/exception.rb', line 16 def to_json(={}) _serialize(:json, ) end |
#to_xml(options = {}) ⇒ Object
12 13 14 |
# File 'lib/exceptron/exception.rb', line 12 def to_xml(={}) _serialize(:xml, ) end |