Exception: Card::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Card::Error
show all
- Defined in:
- lib/card/error.rb
Overview
exceptions and errors.
(arguably most of these should be Card::Exception)
Defined Under Namespace
Classes: Abort, BadQuery, CodenameNotFound, EditConflict, NotFound, PermissionDenied, ServerError, UserError
Constant Summary
collapse
- KEY_MAP =
{ permission_denied: PermissionDenied,
conflict: EditConflict }.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(message = nil) ⇒ Error
Returns a new instance of Error.
15
16
17
18
19
20
21
|
# File 'lib/card/error.rb', line 15
def initialize message=nil
if message.is_a? Card
self.card = message
message = message_from_card
end
super message
end
|
Instance Attribute Details
#card ⇒ Object
Returns the value of attribute card.
13
14
15
|
# File 'lib/card/error.rb', line 13
def card
@card
end
|
Class Method Details
.add_card_errors(card, exception) ⇒ Object
104
105
106
107
|
# File 'lib/card/error.rb', line 104
def add_card_errors card, exception
label = exception.class.to_s.split("::").last
card.errors.add label, exception.message
end
|
.card_error_class(exception, card) ⇒ Object
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/card/error.rb', line 109
def card_error_class exception, card
case exception
when ActiveRecord::RecordInvalid
invalid_card_error_class card
when ActiveRecord::RecordNotFound, ActionController::MissingFile
Card::Error::NotFound
else
Card::Error::ServerError
end
end
|
.cardify_exception(exception, card) ⇒ Object
95
96
97
98
99
100
101
102
|
# File 'lib/card/error.rb', line 95
def cardify_exception exception, card
unless exception.is_a? Card::Error
exception = card_error_class(exception, card).new exception.message
end
exception.card ||= card
add_card_errors card, exception if exception.card.errors.empty?
exception
end
|
.invalid_card_error_class(card) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/card/error.rb', line 120
def invalid_card_error_class card
KEY_MAP.each do |key, klass|
return klass if card.errors.key? key
end
Card::Error
end
|
Instance Method Details
#card_message_text ⇒ Object
32
33
34
|
# File 'lib/card/error.rb', line 32
def card_message_text
card.errors.first&.message
end
|
#message_from_card ⇒ Object
23
24
25
26
|
# File 'lib/card/error.rb', line 23
def message_from_card
I18n.t :exception_for_card,
scope: %i[lib card error], cardname: card.name, message: card_message_text
end
|
#report ⇒ Object
28
29
30
|
# File 'lib/card/error.rb', line 28
def report
Rails.logger.info "exception = #{self.class}: #{message}"
end
|