Module: NeetoCommonsBackend::ApiResponders
- Defined in:
- lib/neeto_commons_backend/controllers/concerns/api_responders.rb
Instance Method Summary collapse
- #render_error(error, status = :unprocessable_entity, context = {}) ⇒ Object
- #render_json(json = {}, status = :ok) ⇒ Object
- #render_message(notice_code, status, **context) ⇒ Object
- #render_notice(notice, context = {}) ⇒ Object
- #render_success(**context) ⇒ Object
Instance Method Details
#render_error(error, status = :unprocessable_entity, context = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/neeto_commons_backend/controllers/concerns/api_responders.rb', line 13 def render_error(error, status = :unprocessable_entity, context = {}) = error is_exception = error.kind_of?(StandardError) if is_exception is_having_record = error.methods.include? "record" = is_having_record ? error.record.errors_to_sentence : error. end = .first if .is_a?(Array) && .length == 1 key = .is_a?(Array) ? "errors" : "error" render_json({ key => }.merge(context), status) end |
#render_json(json = {}, status = :ok) ⇒ Object
29 30 31 |
# File 'lib/neeto_commons_backend/controllers/concerns/api_responders.rb', line 29 def render_json(json = {}, status = :ok) render status:, json: end |
#render_message(notice_code, status, **context) ⇒ Object
5 6 7 |
# File 'lib/neeto_commons_backend/controllers/concerns/api_responders.rb', line 5 def (notice_code, status, **context) render status:, json: { notice_code: }.merge(context) end |
#render_notice(notice, context = {}) ⇒ Object
25 26 27 |
# File 'lib/neeto_commons_backend/controllers/concerns/api_responders.rb', line 25 def render_notice(notice, context = {}) render_json({ notice: }.merge(context)) end |
#render_success(**context) ⇒ Object
9 10 11 |
# File 'lib/neeto_commons_backend/controllers/concerns/api_responders.rb', line 9 def render_success(**context) "thumbs_up", :ok, **context end |