Class: ApiService::ErrorManager
- Inherits:
-
Object
- Object
- ApiService::ErrorManager
- Defined in:
- lib/api_service/error_manager.rb
Instance Method Summary collapse
- #add(field, message, scope = '') ⇒ Object
- #any? ⇒ Boolean
- #from_model(model) ⇒ Object
-
#initialize ⇒ ErrorManager
constructor
A new instance of ErrorManager.
- #to_hash ⇒ Object
Constructor Details
#initialize ⇒ ErrorManager
Returns a new instance of ErrorManager.
3 4 5 |
# File 'lib/api_service/error_manager.rb', line 3 def initialize @errors = {} end |
Instance Method Details
#add(field, message, scope = '') ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/api_service/error_manager.rb', line 11 def add(field, , scope = '') in_scope(scope) do |errors| field = field.to_sym errors[field] ||= [] errors[field] << errors end end |
#any? ⇒ Boolean
7 8 9 |
# File 'lib/api_service/error_manager.rb', line 7 def any? @errors.any? end |
#from_model(model) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/api_service/error_manager.rb', line 24 def from_model(model) model.errors..each do |field, errors| @errors[field] ||= [] @errors[field] = @errors[field].concat(errors).uniq end end |
#to_hash ⇒ Object
20 21 22 |
# File 'lib/api_service/error_manager.rb', line 20 def to_hash @errors end |