Sha256: c9933bef7bc8a9ab0640610434784c12e85b8a9fd4e21e5c559da946e432cc51

Contents?: true

Size: 758 Bytes

Versions: 1

Compression:

Stored size: 758 Bytes

Contents

require "interactor"

module Interactor
  module Strict
    def self.included(base)
      base.class_eval do
        extend ClassMethods
      end
    end

    def initialize(*args, **kargs)
      unless args.empty?
        raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)"
      end

      @kargs = kargs
      @context = Context.build(*args)
    end

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

    module ClassMethods
      def call(*args, **kargs)
        new(*args, **kargs).tap(&:run).context
      end

      def call!(*args, **kargs)
        new(*args, **kargs).tap(&:run!).context
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
interactor-strict-1.0.0 lib/interactor/strict.rb