Sha256: f14bf2ef878ed7060ab9e466bceae59c2c6bfe3ef747e74d78daed94ee497fa5

Contents?: true

Size: 685 Bytes

Versions: 2

Compression:

Stored size: 685 Bytes

Contents

# frozen_string_literal: true

module ProtoPharm
  class RequestPattern
    attr_reader :path, :request, :block

    # @param path [String]
    def initialize(path)
      @path = path
      @block = nil
      @request = nil
    end

    def with(request = nil, &block)
      if request.nil? && !block_given?
        raise ArgumentError, "#with method invoked with no arguments. Either options request or block must be specified."
      end

      @request = request
      @block = block
    end

    def match?(match_path, match_request)
      path == match_path &&
        (request.nil? || request == match_request) &&
        (block.nil? || block.call(match_path))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proto_pharm-0.7.0 lib/proto_pharm/request_pattern.rb
proto_pharm-0.6.0 lib/proto_pharm/request_pattern.rb