Class: Kirei::Services::Result
- Inherits:
-
Object
- Object
- Kirei::Services::Result
- Extended by:
- T::Generic, T::Sig
- Defined in:
- lib/kirei/services/result.rb
Constant Summary collapse
- ErrorType =
type_member { { fixed: T::Array[Errors::JsonApiError] } }
- ResultType =
type_member { { upper: Object } }
Instance Method Summary collapse
- #errors ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(result: nil, errors: []) ⇒ Result
constructor
A new instance of Result.
- #result ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(result: nil, errors: []) ⇒ Result
Returns a new instance of Result.
19 20 21 22 23 24 25 26 |
# File 'lib/kirei/services/result.rb', line 19 def initialize(result: nil, errors: []) if (result && !errors.empty?) || (!result && errors.empty?) raise ArgumentError, "Must provide either result or errors, got both or neither" end @result = result @errors = errors end |
Instance Method Details
#errors ⇒ Object
46 47 48 49 50 |
# File 'lib/kirei/services/result.rb', line 46 def errors raise "Cannot call 'errors' when there is a result" if success? @errors end |
#failed? ⇒ Boolean
34 35 36 |
# File 'lib/kirei/services/result.rb', line 34 def failed? !success? end |
#result ⇒ Object
39 40 41 42 43 |
# File 'lib/kirei/services/result.rb', line 39 def result raise "Cannot call 'result' when there are errors" if failed? T.must(@result) end |
#success? ⇒ Boolean
29 30 31 |
# File 'lib/kirei/services/result.rb', line 29 def success? @errors.empty? end |