Class: ProblemDetails::Document
- Inherits:
-
Object
- Object
- ProblemDetails::Document
- Defined in:
- lib/problem_details/document.rb
Overview
The class that implements a Problem Details JSON object described in RFC 7807.
Instance Attribute Summary collapse
-
#detail ⇒ Object
Returns the value of attribute detail.
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#status ⇒ Object
Returns the value of attribute status.
-
#title ⇒ Object
Returns the value of attribute title.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Document
constructor
A new instance of Document.
- #to_hash ⇒ Object (also: #to_h)
- #to_json ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Document
Returns a new instance of Document.
12 13 14 15 16 17 18 19 20 |
# File 'lib/problem_details/document.rb', line 12 def initialize(params = {}) params = params.dup @type = params.delete(:type) @status = Rack::Utils.status_code(params.delete(:status)) if params.key?(:status) @title = params.delete(:title) || (@status ? ::Rack::Utils::HTTP_STATUS_CODES[@status] : nil) @detail = params.delete(:detail) @instance = params.delete(:instance) @extentions = params end |
Instance Attribute Details
#detail ⇒ Object
Returns the value of attribute detail.
10 11 12 |
# File 'lib/problem_details/document.rb', line 10 def detail @detail end |
#instance ⇒ Object
Returns the value of attribute instance.
10 11 12 |
# File 'lib/problem_details/document.rb', line 10 def instance @instance end |
#status ⇒ Object
Returns the value of attribute status.
10 11 12 |
# File 'lib/problem_details/document.rb', line 10 def status @status end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/problem_details/document.rb', line 10 def title @title end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/problem_details/document.rb', line 10 def type @type end |
Instance Method Details
#to_hash ⇒ Object Also known as: to_h
22 23 24 25 26 27 28 29 |
# File 'lib/problem_details/document.rb', line 22 def to_hash h = {} %i[type title status detail instance].each do |key| value = public_send(key) h[key] = value if value end h.merge(@extentions) end |
#to_json ⇒ Object
32 33 34 |
# File 'lib/problem_details/document.rb', line 32 def to_json to_hash.to_json end |