Class: ApiService::ErrorManager

Inherits:
Object
  • Object
show all
Defined in:
lib/api_service/error_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeErrorManager

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, message, scope = '')
  in_scope(scope) do |errors|
    field = field.to_sym
    errors[field] ||= []
    errors[field] << message
    errors
  end
end

#any?Boolean

Returns:

  • (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.messages.each do |field, errors|
    @errors[field] ||= []
    @errors[field] = @errors[field].concat(errors).uniq
  end
end

#to_hashObject



20
21
22
# File 'lib/api_service/error_manager.rb', line 20

def to_hash
  @errors
end