Sha256: ead7e29b1476308d444968918370d550d04e255a61d56d26bff0434884483ce1
Contents?: true
Size: 1.29 KB
Versions: 18
Compression:
Stored size: 1.29 KB
Contents
# Mixin for the {RailsOps::Operation} class that provides a simple way of # running arbitrary operations within operations, automatically passing a # modified version of the current operation's context to them. module RailsOps::Mixins::SubOps extend ActiveSupport::Concern # Instantiates and returns a new operation of the given class and # automatically passes a modified version of the current operation's context # to it. For one-line runs of operations please use {run_sub!} or {run_sub} # which internally use this method. def sub_op(op, params = {}) new_context = context.spawn(self) return op.new(new_context, params) end # Operation-equivalent of controller method 'run!': Instantiates and runs the # given operation class. See {sub_op} for more details on how instantiation # and context modification is done. def run_sub!(klass, params = {}) op = sub_op(klass, params) begin return op.run! rescue op.validation_errors => e fail RailsOps::Exceptions::SubOpValidationFailed, e end end # Operation-equivalent of controller method 'run': Instantiates and runs the # given operation class. See {sub_op} for more details on how instantiation # and context modification is done. def run_sub(op, params = {}) sub_op(op, params).run end end
Version data entries
18 entries across 18 versions & 1 rubygems