free_mutant/lib/mutant/isolation.rb

38 lines
709 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-09-12 13:15:43 +00:00
2014-06-08 17:55:13 +00:00
module Mutant
# Isolation mechanism
2016-02-14 21:11:32 +00:00
class Isolation
include AbstractType
# Isolated computation result
class Result
include AbstractType
abstract_method :value
abstract_method :error
# Test for success
#
# @return [Boolean]
def success?
instance_of?(Success)
end
class Success < self
include Concord::Public.new(:value)
end # Success
class Error < self
include Concord::Public.new(:error)
end # Error
end # Result
2016-02-14 21:11:32 +00:00
# Call block in isolation
#
# @return [Result]
2016-02-14 21:11:32 +00:00
# the blocks result
abstract_method :call
2016-04-10 14:33:47 -07:00
end # Isolation
end # Mutant