Class: Shamu::JsonApi::ErrorBuilder
- Inherits:
-
Object
- Object
- Shamu::JsonApi::ErrorBuilder
- Includes:
- BuilderMethods::Link, BuilderMethods::Meta
- Defined in:
- lib/shamu/json_api/error_builder.rb
Overview
Build an error response object.
Instance Method Summary collapse
-
#code(code) ⇒ self
Set an application specific error code.
-
#compile ⇒ Hash
The results output as JSON safe hash.
- #detail(message) ⇒ String, self
-
#exception(exception) ⇒ self
Summarize an exception as an error.
-
#http_status(status) ⇒ self
Set an HTTP status code related to the error.
- #id(id) ⇒ self
-
#initialize ⇒ ErrorBuilder
constructor
A new instance of ErrorBuilder.
-
#parameter(name) ⇒ self
The name of the parameter that caused the error.
-
#pointer(pointer) ⇒ self
JSON pointer to the associated document in the request that was the source of the pointer.
-
#title(title) ⇒ self
Set a short human readable title of the error.
Methods included from BuilderMethods::Meta
Methods included from BuilderMethods::Link
Constructor Details
#initialize ⇒ ErrorBuilder
Returns a new instance of ErrorBuilder.
9 10 11 |
# File 'lib/shamu/json_api/error_builder.rb', line 9 def initialize @output = {} end |
Instance Method Details
#code(code) ⇒ self
Set an application specific error code.
46 47 48 49 |
# File 'lib/shamu/json_api/error_builder.rb', line 46 def code( code ) output[:code] = code.to_s self end |
#compile ⇒ Hash
Returns the results output as JSON safe hash.
83 84 85 |
# File 'lib/shamu/json_api/error_builder.rb', line 83 def compile output end |
#detail(message) ⇒ String, self
60 61 62 63 |
# File 'lib/shamu/json_api/error_builder.rb', line 60 def detail( ) output[:detail] = self end |
#exception(exception) ⇒ self
Summarize an exception as an error.
26 27 28 29 30 31 32 33 |
# File 'lib/shamu/json_api/error_builder.rb', line 26 def exception( exception ) name = exception.class.name.demodulize.gsub( /Error$/, "" ) code name.underscore title name.titleize detail exception. self end |
#http_status(status) ⇒ self
Set an HTTP status code related to the error.
38 39 40 41 42 |
# File 'lib/shamu/json_api/error_builder.rb', line 38 def http_status( status ) status = ::Rack::Utils.status_code( status ) if status.is_a? Symbol output[:status] = status.to_s self end |
#id(id) ⇒ self
18 19 20 21 |
# File 'lib/shamu/json_api/error_builder.rb', line 18 def id( id ) output[:id] = id self end |
#parameter(name) ⇒ self
The name of the parameter that caused the error.
76 77 78 79 80 |
# File 'lib/shamu/json_api/error_builder.rb', line 76 def parameter( name ) output[:source] ||= {} output[:source][:parameter] = name self end |
#pointer(pointer) ⇒ self
JSON pointer to the associated document in the request that was the source of the pointer.
68 69 70 71 72 |
# File 'lib/shamu/json_api/error_builder.rb', line 68 def pointer( pointer ) output[:source] ||= {} output[:source][:pointer] = pointer self end |
#title(title) ⇒ self
Set a short human readable title of the error.
53 54 55 56 |
# File 'lib/shamu/json_api/error_builder.rb', line 53 def title( title ) output[:title] = title.to_s self end |