Last active
September 2, 2022 16:15
-
-
Save adamstrickland/cb5ca5b8b9e44a79bbeb1626c109a3fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "./interactor" | |
ctx = SomeInteractor::Context.new(var_a: true) | |
res = SomeInteractor.new(ctx).call | |
assert res.success? | |
res = SomeInteractor.new(var_a: false).call | |
assert res.failure? | |
begin | |
SomeInteractor.new(var_b: :foo).call | |
rescue => e | |
assert e.present? | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeInteractor | |
Context = ImmutableStruct.new(:var_a) | |
attr_reader :context | |
def initialize(ctx, **opts) | |
ctx ||= Context.new(**opts) | |
raise unless ctx.is_a?(Context) | |
@context = ctx | |
end | |
def call | |
return Success(context) if context.var_a | |
Failure("context#var_a is falsy") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment