Sha256: d860762afdf1f25b0424380ebbe4347945674ba3e180c95e0b72854d9dc0c46c

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# frozen_string_literal: true

class BCDD::Result
  module Expectations::Mixin
    METHODS = <<~RUBY
      def Success(...)
        _Result.Success(...)
      end

      def Failure(...)
        _Result.Failure(...)
      end

      private

      def _Result
        @_Result ||= Result.with(subject: self)
      end
    RUBY

    module Addons
      module Continuable
        private def Continue(value)
          Success.new(type: :continued, value: value, subject: self)
        end
      end

      OPTIONS = { Continue: Continuable }.freeze

      def self.options(names)
        Array(names).filter_map { |name| OPTIONS[name] }
      end
    end

    def self.module!
      ::Module.new do
        def self.included(base); base.const_set(:ResultExpectationsMixin, self); end
        def self.extended(base); base.const_set(:ResultExpectationsMixin, self); end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bcdd-result-0.7.0 lib/bcdd/result/expectations/mixin.rb