module
Avram::Callbacks
Direct including types
Defined in:
avram/callbacks/callbacks.crMacro Summary
-
after_run(method_name)
Run the given method after
run
is called on anOperation
. -
after_run(&block)
Run the given block after the operation runs
-
before_run(method_name, if _if = nil, unless _unless = nil)
Run the given method before
run
is called on anOperation
. -
before_run(if _if = nil, unless _unless = nil)
Run the given block before
run
is called on anOperation
.
Macro Detail
Run the given method after run
is called on an Operation
.
The return value of the run
method is passed to method_name
.
after_run :log_entry
private def log_entry(value)
log_stuff(value)
end
Run the given block after the operation runs
The return value from run
will be passed to this block.
class GenerateReport < Avram::Operation
after_run do |value|
value == "some report"
end
def run
"some report"
end
end
Run the given method before run
is called on an Operation
.
Examples:
before_run :validate_inputs
before_run :validate_inputs, if: :should_validate? before_run :validate_inputs, unless: :skip_validation?
private def validate_inputs validate_required data end
Run the given block before run
is called on an Operation
.
This runs before run
is invoked on the operation.
You can set defaults, validate, or perform any other setup necessary before running the operation.
Optionally you can pass an if
or unless
argument which allows you to
run this conditionally. The symbol should reference a method you've defined
that returns a truthy/falsey value.
before_run(unless: :skip_callback?) do
validate_required data
end
private def skip_callback?
false
end