Class: ErrorBuilder::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/error_builder/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/error_builder/engine.rb', line 5

def errors
  @errors
end

#formatObject (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, message)
  error = ErrorBuilder::Error.new(key)
  error.add_message(message)

  @errors << error
end

#formatterObject



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