Class: UseCase::Context::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/usecasing/context.rb

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



7
8
9
# File 'lib/usecasing/context.rb', line 7

def initialize
  @errors = Hash.new { |h,k| h[k.to_sym] = [] }
end

Instance Method Details

#[](index) ⇒ Object



20
21
22
# File 'lib/usecasing/context.rb', line 20

def [](index)
  @errors[index.to_sym]
end

#all(delimiter = ", ", &block) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/usecasing/context.rb', line 11

def all(delimiter= ", ", &block)
  values = @errors.map {|key, value| value }.flatten
  if block_given?
    values.each &block
  else
    values.join(delimiter)
  end
end

#each(&block) ⇒ Object



32
33
34
# File 'lib/usecasing/context.rb', line 32

def each(&block)
  @errors.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/usecasing/context.rb', line 28

def empty?
  @errors.keys.empty?
end

#push(key, value) ⇒ Object



24
25
26
# File 'lib/usecasing/context.rb', line 24

def push(key, value)
  @errors[key.to_sym].push(value)
end