Class: ErrorBuilder::Error
- Inherits:
-
Object
- Object
- ErrorBuilder::Error
- Defined in:
- lib/error_builder/error.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #add_message(message) ⇒ Object
-
#initialize(key) ⇒ Error
constructor
A new instance of Error.
- #keys ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(key) ⇒ Error
Returns a new instance of Error.
7 8 9 10 11 |
# File 'lib/error_builder/error.rb', line 7 def initialize(key) @key = key @format = ErrorBuilder.configuration. @message = (format) end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/error_builder/error.rb', line 5 def format @format end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/error_builder/error.rb', line 5 def key @key end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/error_builder/error.rb', line 5 def @message end |
Instance Method Details
#add_message(message) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/error_builder/error.rb', line 13 def () case format when :array @message << when :string @message = else raise ArgumentError, "Unsupported message format: #{format}" end end |
#keys ⇒ Object
31 32 33 34 35 |
# File 'lib/error_builder/error.rb', line 31 def keys return [key] unless key.to_s.include?(".") deflat_key end |
#to_h ⇒ Object
24 25 26 27 28 29 |
# File 'lib/error_builder/error.rb', line 24 def to_h { key: @key, message: @message } end |