Class: Core::Boundary::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/core/boundary/errors.rb

Overview

public

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



8
9
10
# File 'lib/core/boundary/errors.rb', line 8

def initialize
  @errors = {}
end

Instance Method Details

#add(*path, message) ⇒ Object

public


14
15
16
# File 'lib/core/boundary/errors.rb', line 14

def add(*path, message)
  (@errors[normalize_path(path)] ||= []) << message
end

#any?(*path) ⇒ Boolean

public

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/core/boundary/errors.rb', line 38

def any?(*path)
  if path.empty?
    @errors.any?
  else
    errors = @errors[normalize_path(path)]
    !!errors && errors.any?
  end
end

#each(&block) ⇒ Object

public


26
27
28
29
30
31
32
33
34
# File 'lib/core/boundary/errors.rb', line 26

def each(&block)
  return to_enum(:each) unless block

  @errors.each_pair do |path, errors|
    errors.each do |error|
      yield path, error
    end
  end
end

#empty?(*path) ⇒ Boolean

public

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
# File 'lib/core/boundary/errors.rb', line 49

def empty?(*path)
  if path.empty?
    @errors.empty?
  else
    errors = @errors[normalize_path(path)]
    !errors || errors.empty?
  end
end

#for(*path) ⇒ Object

public


60
61
62
# File 'lib/core/boundary/errors.rb', line 60

def for(*path)
  @errors.fetch(path) { [] }
end

#merge!(*merge_path, errors) ⇒ Object



18
19
20
21
22
# File 'lib/core/boundary/errors.rb', line 18

def merge!(*merge_path, errors)
  errors.each do |path, error|
    add(*merge_path, *normalize_path(path), error)
  end
end