-
Notifications
You must be signed in to change notification settings - Fork 14
Using an Op
Mike Nelson edited this page Jan 29, 2020
·
1 revision
The Subroutine::Op
class' submit
and submit!
methods have identical signatures to the class' constructor, enabling a few different ways to utilize an op:
op = MyOp.submit({foo: 'bar'})
# if the op succeeds it will be returned, otherwise false will be returned.
op = MyOp.submit!({foo: 'bar'})
# if the op succeeds it will be returned, otherwise a ::Subroutine::Failure will be raised.
op = MyOp.new({foo: 'bar'})
val = op.submit
# if the op succeeds, val will be true, otherwise false
op = MyOp.new({foo: 'bar'})
op.submit!
# if the op succeeds nothing will be raised, otherwise a ::Subroutine::Failure will be raised.
Outputs can be used after an Op is invoked.
class MyOp
string :first_name
outputs :first_name_reversed
validates :first_name, presence: true
def perform
output :first_name_reversed, first_name.reverse
end
end
op = MyOp.submit!({ first_name: "bar" })
op.outputs # => { first_name_reversed: "rab" }
op.first_name_reversed # => "rab"