lib/interactor.rb in interactor-2.1.1 vs lib/interactor.rb in interactor-3.0.0
- old
+ new
@@ -1,54 +1,50 @@
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 perform(context = {})
- new(context).tap do |instance|
- instance.perform unless instance.failure?
- end
+ 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)
- setup
end
- def setup
+ def run
+ run!
+ rescue Failure
end
- def perform
+ def run!
+ with_hooks do
+ call
+ context.called!(self)
+ end
+ rescue
+ context.rollback!
+ raise
end
- def rollback
+ def call
end
- def success?
- context.success?
- end
-
- def failure?
- context.failure?
- end
-
- def fail!(*args)
- context.fail!(*args)
- end
-
- def method_missing(method, *)
- context.fetch(method) { context.fetch(method.to_s) { super } }
- end
-
- def respond_to_missing?(method, *)
- (context && (context.key?(method) || context.key?(method.to_s))) || super
+ def rollback
end
end