Class: Lev::Error
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#data ⇒ Object
Returns the value of attribute data.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#message ⇒ Object
Returns the value of attribute message.
-
#offending_inputs ⇒ Object
The inputs related to this error.
Instance Method Summary collapse
- #full_message ⇒ Object
-
#initialize(args = {}) ⇒ Error
constructor
A new instance of Error.
- #to_s ⇒ Object
- #translate ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Error
Returns a new instance of Error.
13 14 15 16 17 18 19 20 21 |
# File 'lib/lev/error.rb', line 13 def initialize(args={}) raise ArgumentError, "must supply a :code" if args[:code].blank? self.code = args[:code] self.data = args[:data] self.kind = args[:kind] self. = args[:message] self.offending_inputs = args[:offending_inputs] end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/lev/error.rb', line 5 def code @code end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/lev/error.rb', line 6 def data @data end |
#kind ⇒ Object
Returns the value of attribute kind.
7 8 9 |
# File 'lib/lev/error.rb', line 7 def kind @kind end |
#message ⇒ Object
Returns the value of attribute message.
8 9 10 |
# File 'lib/lev/error.rb', line 8 def @message end |
#offending_inputs ⇒ Object
The inputs related to this error
11 12 13 |
# File 'lib/lev/error.rb', line 11 def offending_inputs @offending_inputs end |
Instance Method Details
#full_message ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lev/error.rb', line 31 def attribute = data[:attribute] if data.present? return .humanize if attribute.nil? attr_name = attribute.to_s.gsub('.', '_').humanize model = data[:model] attr_name = model.class.human_attribute_name(attribute, default: attr_name) if model.present? I18n.t(:"errors.format", { default: "%{attribute} %{message}", attribute: attr_name, message: }) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/lev/error.rb', line 27 def to_s inspect end |
#translate ⇒ Object
23 24 25 |
# File 'lib/lev/error.rb', line 23 def translate ErrorTranslator.translate(self) end |