Sha256: 3816afebff8bd579d60e969d8b42a1f7ec889b3ae5b7a47e4252a990772d21d6

Contents?: true

Size: 1.41 KB

Versions: 8

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Mutant
  # Isolation mechanism
  class Isolation
    include AbstractType

    # Isolated computation result
    class Result
      include AbstractType, Adamantium

      NULL_LOG = ''

      private_constant(*constants(false))

      abstract_method :error
      abstract_method :next
      abstract_method :value

      # Add error on top of current result
      #
      # @param [Result] error
      #
      # @return [Result]
      def add_error(error)
        ErrorChain.new(error, self)
      end

      # The log captured from integration
      #
      # @return [String]
      def log
        NULL_LOG
      end

      # Test for success
      #
      # @return [Boolean]
      def success?
        instance_of?(Success)
      end

      # Successful result producing value
      class Success < self
        include Concord::Public.new(:value, :log)

        def self.new(_value, _log = '')
          super
        end
      end # Success

      # Unsuccessful result by unexpected exception
      class Exception < self
        include Concord::Public.new(:value)
      end # Error

      # Result when there where many results
      class ErrorChain < Result
        include Concord::Public.new(:value, :next)
      end # ChainError
    end # Result

    # Call block in isolation
    #
    # @return [Result]
    #   the blocks result
    abstract_method :call
  end # Isolation
end # Mutant

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mutant-0.10.6 lib/mutant/isolation.rb
mutant-0.10.5 lib/mutant/isolation.rb
mutant-0.10.4 lib/mutant/isolation.rb
mutant-0.10.1 lib/mutant/isolation.rb
mutant-0.10.0 lib/mutant/isolation.rb
mutant-0.9.14 lib/mutant/isolation.rb
mutant-0.9.13 lib/mutant/isolation.rb
mutant-0.9.12 lib/mutant/isolation.rb