Sha256: ae539342fa617a70a84ab7f09dccaa5578b228bf79c4181522e76abc1c2b5831

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

# frozen_string_literal: true

module ProtoPharm
  module Response
    class ExceptionValue
      attr_reader :exception

      def initialize(exception)
        @exception = case exception
                     when String
                       StandardError.new(exception)
                     when Class
                       exception.new("Exception from ProtoPharm")
                     when Exception
                       exception
                     else
                       raise ArgumentError.new(message: "Invalid exception class: #{exception.class}")
                     end
      end

      def evaluate(_request = nil)
        raise @exception.dup
      end
    end

    class Value
      attr_reader :value

      def initialize(value)
        @value = value
      end

      def evaluate(request = nil)
        if value.respond_to?(:call)
          value.call(request)
        else
          value.dup
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proto_pharm-0.7.0 lib/proto_pharm/response.rb