Module: ActsResponsible::Core
- Defined in:
- lib/acts_responsible/core.rb
Instance Method Summary collapse
- #render_empty_response(options = {}) ⇒ Object
- #render_error(status, errors = [], options = {}) ⇒ Object
- #render_response(data, data_key, template, options = {}) ⇒ Object
Instance Method Details
#render_empty_response(options = {}) ⇒ Object
19 20 21 |
# File 'lib/acts_responsible/core.rb', line 19 def render_empty_response(={}) render_response(nil, nil, nil, ) end |
#render_error(status, errors = [], options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acts_responsible/core.rb', line 23 def render_error(status, errors=[], ={}) @responsibility ||= {} response_errors = [] if errors.is_a? ActiveModel::Errors errors.keys.each do |field| errors.(field).each do || response_errors << {field: field, detail: } end end else response_errors = Array.wrap(errors) end @responsibility[:errors] = response_errors [:status] = status render_empty_response end |
#render_response(data, data_key, template, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/acts_responsible/core.rb', line 4 def render_response(data, data_key, template, ={}) prefix = self.responsible_config[:prefix] @responsibility ||= {} @responsibility.merge!({ data_key: data_key, data: data, metadata: .delete(:meta), partial: "#{prefix}/#{template}" }) .merge!(template: 'acts_responsible/response') render end |