Sha256: 47838152d32e99148e0b52239465c7b29d5ed5fc22ba03b888c98c4cd0e45ca1

Contents?: true

Size: 866 Bytes

Versions: 1

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

class BCDD::Result::Context
  module Mixin
    module Methods
      def Success(type, **value)
        Success.new(type: type, value: value, subject: self)
      end

      def Failure(type, **value)
        Failure.new(type: type, value: value, subject: self)
      end
    end

    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
  end

  def self.mixin(with: nil)
    addons = Mixin::Addons.options(with)

    mod = ::BCDD::Result::Mixin.module!
    mod.send(:include, Mixin::Methods)
    mod.send(:include, *addons) unless addons.empty?
    mod
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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