Class: UseCase::Context::Errors
- Inherits:
-
Object
- Object
- UseCase::Context::Errors
- Defined in:
- lib/usecasing/context.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
- #all(delimiter = ", ", &block) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Errors
constructor
A new instance of Errors.
- #push(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Errors
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
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 |