Class: Exceptron::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptron/exception.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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

.statusesObject

Returns the value of attribute statuses.



8
9
10
# File 'lib/exceptron/exception.rb', line 8

def statuses
  @statuses
end

Instance Attribute Details

#wrapped_exceptionObject (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

#actionsObject



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_exceptionObject



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_codeObject



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_messageObject



26
27
28
29
# File 'lib/exceptron/exception.rb', line 26

def status_message
  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(options={})
  _serialize(:json, options)
end

#to_xml(options = {}) ⇒ Object



12
13
14
# File 'lib/exceptron/exception.rb', line 12

def to_xml(options={})
  _serialize(:xml, options)
end