Module: WebMock::Twirp::RequestSignature

Defined in:
lib/webmock/twirp/request_signature.rb

Instance Method Summary collapse

Instance Method Details

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/webmock/twirp/request_signature.rb', line 29

def to_s
  return super unless twirp_rpc

  uri = WebMock::Util::URI.strip_default_port_from_uri_string(self.uri.to_s)
  params = twirp_request.normalized_hash.map do |k, v|
    "#{k}: #{v.inspect}"
  end.join(", ")

  string = "#{twirp_client}(#{uri})"
  string << ".#{twirp_rpc[:ruby_method]}"
  string << "(#{params.empty? ? "{}" : params})"

  string
end

#twirp_clientObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/webmock/twirp/request_signature.rb', line 6

def twirp_client
  @twirp_client ||= begin
    service_full_name, rpc_name = uri.path.split("/").last(2)

    # find matching client
    client = ObjectSpace.each_object(::Twirp::Client.singleton_class).find do |obj|
      next unless obj < ::Twirp::Client && obj.name
      obj.service_full_name == service_full_name && obj.rpcs.key?(rpc_name)
    end
  end
end

#twirp_requestObject



25
26
27
# File 'lib/webmock/twirp/request_signature.rb', line 25

def twirp_request
  twirp_rpc[:input_class].decode(body) if twirp_rpc
end

#twirp_rpcObject



18
19
20
21
22
23
# File 'lib/webmock/twirp/request_signature.rb', line 18

def twirp_rpc
  @twirp_rpc ||= begin
    rpc_name = uri.path.split("/").last
    client = twirp_client.rpcs[rpc_name] if twirp_client
  end
end