class ProtoPharm::ActionStub

Attributes

action[R]
service[R]

Public Class Methods

new(service, action) click to toggle source

@param service [GRPC::GenericService] gRPC service class representing the the service being stubbed @param action [String, Symbol] name of the endpoint being stubbed

Calls superclass method
# File lib/proto_pharm/action_stub.rb, line 12
def initialize(service, action)
  @service = service
  @action = action

  super(grpc_path)
end

Public Instance Methods

match?(match_path, match_request) click to toggle source
Calls superclass method
# File lib/proto_pharm/action_stub.rb, line 45
def match?(match_path, match_request)
  # If paths don't match, don't try to cast the request object
  super unless grpc_path == match_path

  # If paths match, cast the given request object to the expected proto
  super(match_path, endpoint.normalize_request_proto(match_request))
end
received!(request) click to toggle source
# File lib/proto_pharm/action_stub.rb, line 37
def received!(request)
  @received_requests << request
end
received_count() click to toggle source
# File lib/proto_pharm/action_stub.rb, line 41
def received_count
  received_requests.size
end
to_return(proto = nil, **request_kwargs, &block) click to toggle source

@param proto [Object] response proto object @param request_kwargs [Hash] parameters to respond with

Calls superclass method
# File lib/proto_pharm/action_stub.rb, line 27
def to_return(proto = nil, **request_kwargs, &block)
  if block_given?
    raise ArgumentError, "Cannot stub with static response if stubbing with a block" if proto.present? || request_kwargs.present?

    return super(&block)
  end

  super(endpoint.normalize_response_proto(proto, **request_kwargs))
end
with(proto = nil, **request_kwargs) click to toggle source

@param proto [Object] request proto object @param request_kwargs [Hash] parameters for request

Calls superclass method
# File lib/proto_pharm/action_stub.rb, line 21
def with(proto = nil, **request_kwargs)
  super(endpoint.normalize_request_proto(proto, **request_kwargs))
end

Private Instance Methods

endpoint() click to toggle source
# File lib/proto_pharm/action_stub.rb, line 57
def endpoint
  @endpoint ||= inspect_rpc(service, action)
end