lib/micro/case/result/wrapper.rb in u-case-4.2.1 vs lib/micro/case/result/wrapper.rb in u-case-4.2.2
- old
+ new
@@ -2,40 +2,45 @@
module Micro
class Case
class Result
class Wrapper
- def initialize(result)
- @__is_unknown = true
+ attr_reader :output
+ def initialize(result)
@result = result
+ @output = ::Kind::Undefined
+
+ @__is_unknown = true
end
def failure(type = nil)
- return if @result.success?
+ return if @result.success? || !undefined_output?
- if result_type?(type)
- @__is_unknown = false
-
- yield(@result)
- end
+ set_output(yield(@result)) if result_type?(type)
end
def success(type = nil)
- return if @result.failure?
+ return if @result.failure? || !undefined_output?
- if result_type?(type)
- @__is_unknown = false
-
- yield(@result)
- end
+ set_output(yield(@result)) if result_type?(type)
end
def unknown
- return yield(@result) if @__is_unknown
+ @output = yield(@result) if @__is_unknown && undefined_output?
end
private
+
+ def set_output(value)
+ @__is_unknown = false
+
+ @output = value
+ end
+
+ def undefined_output?
+ ::Kind::Undefined == @output
+ end
def result_type?(type)
type.nil? || @result.type == type
end
end