Sha256: 513c5695e2ed5ab4c79c319ba67c7aa13b54f1b81ede66463672be1b94ac0bc8

Contents?: true

Size: 1.29 KB

Versions: 60

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

60 entries across 60 versions & 1 rubygems

Version Path
rails_ops-1.4.3 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.4.2 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.0.17.1 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.4.1 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.4.0 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.3.0 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.2.3 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.2.2 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.2.1 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.2.0 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.31 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.30 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.29 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.28 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.27 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.26 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.25 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.24 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.23 lib/rails_ops/mixins/sub_ops.rb
rails_ops-1.1.22 lib/rails_ops/mixins/sub_ops.rb