lib/fluxo/result.rb in fluxo-0.1.0 vs lib/fluxo/result.rb in fluxo-0.2.0

- old
+ new

@@ -1,10 +1,11 @@ # frozen_string_literal: true module Fluxo class Result - attr_reader :operation, :type, :value, :ids + attr_reader :operation, :type, :value + attr_accessor :ids # @param options [Hash] # @option options [Fluxo::Operation] :operation The operation instance that gererated this result # @option options [symbol] :type The type of the result. Allowed types: :ok, :failure, :exception # @option options [Any] :value The value of the result. @@ -29,18 +30,18 @@ # @return [Boolean] true if the result is an exception def error? type == :exception end - def on_success(handler_id = nil) - tap { yield(self) if success? && (handler_id.nil? || ids.include?(handler_id)) } + def on_success(*handler_ids) + tap { yield(self) if success? && (handler_ids.none? || (ids & handler_ids).any?) } end - def on_failure(handler_id = nil) - tap { yield(self) if failure? && (handler_id.nil? || ids.include?(handler_id)) } + def on_failure(*handler_ids) + tap { yield(self) if failure? && (handler_ids.none? || (ids & handler_ids).any?) } end - def on_error(handler_id = nil) - tap { yield(self) if error? && (handler_id.nil? || ids.include?(handler_id)) } + def on_error(*handler_ids) + tap { yield(self) if error? && (handler_ids.none? || (ids & handler_ids).any?) } end end end