Sha256: 7e92ef5b94021555bff57e846558c10237f96a28526ebf2cd9f2580a32e8d9d7

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

class BCDD::Result
  module Expectations::Mixin
    module Factory
      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

    module Methods
      BASE = <<~RUBY
        def Success(...)
          _Result.Success(...)
        end

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

      FACTORY = <<~RUBY
        private def _Result
          @_Result ||= Result.with(subject: self, terminal: %<terminal>s)
        end
      RUBY

      def self.to_eval(addons)
        terminal = addons.key?(:continue) ? 'true' : 'nil'

        "#{BASE}\n#{format(FACTORY, terminal: terminal)}"
      end
    end

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

      module Given
        private def Given(value)
          Success.new(type: :given, value: value, subject: self)
        end
      end

      OPTIONS = { continue: Continue, given: Given }.freeze

      def self.options(config_flags)
        Config::Options.addon(map: config_flags, from: OPTIONS)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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