Class: ErrorBuilder::Engine
- Inherits:
-
Object
- Object
- ErrorBuilder::Engine
- Defined in:
- lib/error_builder/engine.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
Instance Method Summary collapse
- #add(key, message) ⇒ Object
- #formatter ⇒ Object
-
#initialize(format: ErrorBuilder.configuration.format) ⇒ Engine
constructor
A new instance of Engine.
- #to_h(flat: false) ⇒ Object
Constructor Details
#initialize(format: ErrorBuilder.configuration.format) ⇒ Engine
Returns a new instance of Engine.
7 8 9 10 |
# File 'lib/error_builder/engine.rb', line 7 def initialize(format: ErrorBuilder.configuration.format) @format = format @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/error_builder/engine.rb', line 5 def errors @errors end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/error_builder/engine.rb', line 5 def format @format end |
Instance Method Details
#add(key, message) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/error_builder/engine.rb', line 12 def add(key, ) error = ErrorBuilder::Error.new(key) error.() @errors << error end |
#formatter ⇒ Object
23 24 25 |
# File 'lib/error_builder/engine.rb', line 23 def formatter FormatResolver.new(format).formatter end |
#to_h(flat: false) ⇒ Object
19 20 21 |
# File 'lib/error_builder/engine.rb', line 19 def to_h(flat: false) formatter.new(errors, flat:).to_h end |