lib/fluxo/result.rb in fluxo-0.2.1 vs lib/fluxo/result.rb in fluxo-0.3.0

- old
+ new

@@ -1,10 +1,11 @@ # frozen_string_literal: true module Fluxo class Result - attr_reader :operation, :type, :value, :ids + ATTRIBUTES = %i[operation type value ids transient_attributes].freeze + attr_reader(*ATTRIBUTES) # @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. @@ -12,13 +13,17 @@ def initialize(operation:, type:, value:, ids: nil) @operation = operation @value = value @type = type @ids = Array(ids) + @transient_attributes = {} end def mutate(**attrs) - self.class.new(**{operation: operation, type: type, value: value, ids: ids}.merge(attrs)) + attrs.each do |key, value| + instance_variable_set("@#{key}", value) if ATTRIBUTES.include?(key) + end + self end def ==(other) other.is_a?(self.class) && other.operation == operation && other.type == type && other.value == value && other.ids == ids end