Module: Card::Format::Error

Included in:
Card::Format
Defined in:
lib/card/format/error.rb

Instance Method Summary collapse

Instance Method Details

#anyone_can?(task) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/card/format/error.rb', line 9

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



46
47
48
49
50
51
52
# File 'lib/card/format/error.rb', line 46

def error_cardname _exception
  if card&.name.present?
    safe_name
  else
    ::I18n.t :lib_no_cardname
  end
end

#loud_error(e, view) ⇒ Object



58
59
60
61
62
# File 'lib/card/format/error.rb', line 58

def loud_error e, view
  e.report if focal? && voo.root?
  card.errors.add "#{view} view", rendering_error(e, view) if card.errors.empty?
  raise e
end

#loud_error?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/card/format/error.rb', line 54

def loud_error?
  focal? || Card.config.raise_all_rendering_errors
end

#monitor_depthObject



32
33
34
35
36
37
38
39
# File 'lib/card/format/error.rb', line 32

def monitor_depth
  max = Card.config.max_depth
  if depth >= max || voo.depth >= max
    raise Card::Error::UserError, t(:format_too_deep)
  end

  yield
end

#ok?(task) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
# File 'lib/card/format/error.rb', line 4

def ok? task
  task = :create if task == :update && card.new_card?
  card.ok? task
end

#quiet_error(e, view) ⇒ Object



64
65
66
67
# File 'lib/card/format/error.rb', line 64

def quiet_error e, view
  e.report
  rendering_error e, view
end

#rendering_error(exception, view) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/card/format/error.rb', line 69

def rendering_error exception, view
  if exception.is_a? Card::Error::UserError
    exception.message
  else
    t :lib_error_rendering, cardname: error_cardname(exception), view: view
  end
end

#rescue_view(e, view) ⇒ Object



41
42
43
44
# File 'lib/card/format/error.rb', line 41

def rescue_view e, view
  method = loud_error? ? :loud_error : :quiet_error
  send method, e, view
end

#view_for_denial(view, task) ⇒ Object



26
27
28
29
30
# File 'lib/card/format/error.rb', line 26

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(setting_view) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/card/format/error.rb', line 17

def view_for_unknown setting_view
  if main? && voo.root?
    root.error_status = 404
    :not_found
  else
    setting_view || :unknown
  end
end