Sha256: cf5fc3a8d9d0c7866e4a8f5cbb4e53dd4efc8db689f6ce0f05473cb3dcbd8b5f

Contents?: true

Size: 735 Bytes

Versions: 1

Compression:

Stored size: 735 Bytes

Contents

require "interactor/context"
require "interactor/error"
require "interactor/hooks"
require "interactor/organizer"

module Interactor
  def self.included(base)
    base.class_eval do
      extend ClassMethods
      include Hooks

      attr_reader :context
    end
  end

  module ClassMethods
    def call(context = {})
      new(context).tap(&:run).context
    end

    def call!(context = {})
      new(context).tap(&:run!).context
    end
  end

  def initialize(context = {})
    @context = Context.build(context)
  end

  def run
    run!
  rescue Failure
  end

  def run!
    with_hooks do
      call
      context.called!(self)
    end
  rescue
    context.rollback!
    raise
  end

  def call
  end

  def rollback
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interactor-3.0.0 lib/interactor.rb