Skip to content
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:

Via the class' submit method

op = MyOp.submit({foo: 'bar'})
# if the op succeeds it will be returned, otherwise false will be returned.

Via the class' submit! method

op = MyOp.submit!({foo: 'bar'})
# if the op succeeds it will be returned, otherwise a ::Subroutine::Failure will be raised.

Via the instance's submit method

op = MyOp.new({foo: 'bar'})
val = op.submit
# if the op succeeds, val will be true, otherwise false

Via the instance's submit! method

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"