Sha256: 22b1e64b2e70ef0828eb4874d00a139718d58ec6e8e85c850cfb8556ceb8be2d

Contents?: true

Size: 1.41 KB

Versions: 12

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

      # Succesful 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

12 entries across 12 versions & 1 rubygems

Version Path
mutant-0.9.11 lib/mutant/isolation.rb
mutant-0.9.10 lib/mutant/isolation.rb
mutant-0.9.9 lib/mutant/isolation.rb
mutant-0.9.8 lib/mutant/isolation.rb
mutant-0.9.7 lib/mutant/isolation.rb
mutant-0.9.6 lib/mutant/isolation.rb
mutant-0.9.5 lib/mutant/isolation.rb
mutant-0.9.4 lib/mutant/isolation.rb
mutant-0.9.3 lib/mutant/isolation.rb
mutant-0.9.2 lib/mutant/isolation.rb
mutant-0.9.1 lib/mutant/isolation.rb
mutant-0.9.0 lib/mutant/isolation.rb