Sha256: a35bb7cbb8225b19551e47b34e501ebbf56a7385fe1ff18c68c1f1286736b204

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Micro
  class Case
    class Result
      class Wrapper
        attr_reader :output

        def initialize(result)
          @result = result
          @output = ::Kind::Undefined

          @__is_unknown = true
        end

        def failure(type = nil)
          return if @result.success? || !undefined_output?

          set_output(yield(@result)) if result_type?(type)
        end

        def success(type = nil)
          return if @result.failure? || !undefined_output?

          set_output(yield(@result)) if result_type?(type)
        end

        def 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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
u-case-4.5.2 lib/micro/case/result/wrapper.rb
u-case-4.5.1 lib/micro/case/result/wrapper.rb
u-case-4.5.0 lib/micro/case/result/wrapper.rb
u-case-4.4.0 lib/micro/case/result/wrapper.rb
u-case-4.3.0 lib/micro/case/result/wrapper.rb
u-case-4.2.2 lib/micro/case/result/wrapper.rb