Module: Card::Format::Error
- Included in:
- Card::Format
- Defined in:
- lib/card/format/error.rb
Instance Method Summary collapse
- #anyone_can?(task) ⇒ Boolean
- #error_cardname(_exception) ⇒ Object
- #loud_error(e, view) ⇒ Object
- #loud_error? ⇒ Boolean
- #monitor_depth ⇒ Object
- #ok?(task) ⇒ Boolean
- #quiet_error(e, view) ⇒ Object
- #rendering_error(exception, view) ⇒ Object
- #rescue_view(e, view) ⇒ Object
- #view_for_denial(view, task) ⇒ Object
- #view_for_unknown(_view) ⇒ Object
Instance Method Details
#anyone_can?(task) ⇒ Boolean
11 12 13 14 15 16 |
# File 'lib/card/format/error.rb', line 11 def anyone_can? task return false unless task.is_a? Symbol @anyone_can ||= {} @anyone_can[task] = card.anyone_can? task if @anyone_can[task].nil? @anyone_can[task] end |
#error_cardname(_exception) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/card/format/error.rb', line 43 def error_cardname _exception if card&.name.present? safe_name else I18n.t :no_cardname, scope: %i[lib card format error] end end |
#loud_error(e, view) ⇒ Object
55 56 57 58 |
# File 'lib/card/format/error.rb', line 55 def loud_error e, view card.errors.add "#{view} view", rendering_error(e, view) if card.errors.empty? raise e end |
#loud_error? ⇒ Boolean
51 52 53 |
# File 'lib/card/format/error.rb', line 51 def loud_error? focal? || Card.config.raise_all_rendering_errors end |
#monitor_depth ⇒ Object
33 34 35 36 |
# File 'lib/card/format/error.rb', line 33 def monitor_depth raise Card::Error::UserError, tr(:too_deep) if depth >= Card.config.max_depth yield end |
#ok?(task) ⇒ Boolean
4 5 6 7 8 9 |
# File 'lib/card/format/error.rb', line 4 def ok? task task = :create if task == :update && card.new_card? @ok ||= {} @ok[task] = card.ok? task if @ok[task].nil? @ok[task] end |
#quiet_error(e, view) ⇒ Object
60 61 62 63 64 |
# File 'lib/card/format/error.rb', line 60 def quiet_error e, view # TODO: unify with Card::Error#report Rails.logger.info "#{e.}\n" + (e.backtrace * "\n") rendering_error e, view end |
#rendering_error(exception, view) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/card/format/error.rb', line 66 def rendering_error exception, view if exception.is_a? Card::Error::UserError exception. else tr :error_rendering, scope: %i[lib card format error], cardname: error_cardname(exception), view: view end end |
#rescue_view(e, view) ⇒ Object
38 39 40 41 |
# File 'lib/card/format/error.rb', line 38 def rescue_view e, view method = loud_error? ? :loud_error : :quiet_error send method, e, view end |
#view_for_denial(view, task) ⇒ Object
27 28 29 30 31 |
# File 'lib/card/format/error.rb', line 27 def view_for_denial view, task @denied_task = task root.error_status = 403 if focal? && voo.root? view_setting(:denial, view) || :denial end |
#view_for_unknown(_view) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/card/format/error.rb', line 18 def view_for_unknown _view if main? root.error_status = 404 :not_found else :missing end end |