Module: Lab42::Result::Errors
- Defined in:
- lib/lab42/result/errors.rb
Instance Method Summary collapse
- #add_errors(*errs) ⇒ Object
- #errors ⇒ Object
- #if_error(&blk) ⇒ Object
- #if_ok(&blk) ⇒ Object
- #ok? ⇒ Boolean
- #to_result(value = self, exception: nil) ⇒ Object
Instance Method Details
#add_errors(*errs) ⇒ Object
6 |
# File 'lib/lab42/result/errors.rb', line 6 def add_errors(*errs) = errs.flatten.each { errors << it } |
#errors ⇒ Object
8 9 10 |
# File 'lib/lab42/result/errors.rb', line 8 def errors @__errors__ ||= [] end |
#if_error(&blk) ⇒ Object
12 13 14 |
# File 'lib/lab42/result/errors.rb', line 12 def if_error(&blk) ok? || blk.(self) end |
#if_ok(&blk) ⇒ Object
16 17 18 |
# File 'lib/lab42/result/errors.rb', line 16 def if_ok(&blk) ok? && blk.(self) end |
#ok? ⇒ Boolean
20 |
# File 'lib/lab42/result/errors.rb', line 20 def ok? = errors.empty? |
#to_result(value = self, exception: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lab42/result/errors.rb', line 22 def to_result(value = self, exception: nil) if ok? Result.ok(value) else if exception Result.error(errors, exception:) else Result.error(errors) end end end |