Class: Josh::Respond
- Defined in:
- lib/respond.rb,
lib/respond/version.rb
Constant Summary collapse
- VERSION =
"0.1.5"
Instance Attribute Summary
Attributes inherited from Messages
#code, #config, #error, #error_code, #headers, #lang, #text
Instance Method Summary collapse
-
#respond_with_message(message = nil) ⇒ Object
get respond with message.
-
#respond_with_result(data) ⇒ Object
get respond with result.
-
#set_error_code(error_code) ⇒ Object
set error code and get details from lang file.
-
#set_headers(headers) ⇒ Object
set headers for response.
-
#set_status_code(code) ⇒ Object
set status code of respond.
-
#set_status_text(text) ⇒ Object
set status text of respond.
Methods inherited from Messages
#connection_refused, #delete_failed, #delete_succeeded, #initialize, #insert_failed, #insert_succeeded, #method_not_allowed, #not_found, #request_field_duplicated, #request_field_notfound, #succeed, #update_failed, #update_succeeded, #validation_errors, #wrong_parameters
Constructor Details
This class inherits a constructor from Josh::Messages
Instance Method Details
#respond_with_message(message = nil) ⇒ Object
get respond with message
277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/respond.rb', line 277 def ( = nil) result = { :status => @text , :message => } if == nil result['message'] = @error[:message] end if @error_code result['error'] = @error_code end { :json => result, status: @code, headers: @headers } end |
#respond_with_result(data) ⇒ Object
get respond with result
298 299 300 301 |
# File 'lib/respond.rb', line 298 def respond_with_result(data) { :json => { :status => @text, :result => data }, status: @code, headers: @headers } end |
#set_error_code(error_code) ⇒ Object
set error code and get details from lang file
310 311 312 313 314 |
# File 'lib/respond.rb', line 310 def set_error_code(error_code) @error_code = error_code @error = I18n.t "respond.#{error_code}" self end |
#set_headers(headers) ⇒ Object
set headers for response
323 324 325 |
# File 'lib/respond.rb', line 323 def set_headers(headers) @headers = headers end |
#set_status_code(code) ⇒ Object
set status code of respond
253 254 255 256 |
# File 'lib/respond.rb', line 253 def set_status_code(code) @code = code self end |
#set_status_text(text) ⇒ Object
set status text of respond
265 266 267 268 |
# File 'lib/respond.rb', line 265 def set_status_text(text) @text = I18n.t text self end |