Class: GrpcMock::RequestPattern

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc_mock/request_pattern.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RequestPattern

Returns a new instance of RequestPattern.

Parameters:

  • path (String)


6
7
8
9
10
# File 'lib/grpc_mock/request_pattern.rb', line 6

def initialize(path)
  @path = path
  @block = nil
  @request = nil
end

Instance Method Details

#match?(path, request) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/grpc_mock/request_pattern.rb', line 21

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

#with(request = nil, &block) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/grpc_mock/request_pattern.rb', line 12

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