Class: Gapic::Presenters::Method::HttpBindingPresenter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gapic/presenters/method/http_binding_presenter.rb

Overview

A presenter for the Http Binding, used to generate code setting up gRPC transcoding

Instance Method Summary collapse

Constructor Details

#initialize(binding) ⇒ HttpBindingPresenter



26
27
28
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 26

def initialize binding
  @binding = binding
end

Instance Method Details

#bodyString



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#body?Boolean



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#pathString



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#path?Boolean



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#routing_params?Boolean



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#routing_params_transcoder_field_binding_stringsArray<String>

The strings to initialize the bindings parameter when initializing a gapic http binding. The bindings parameter is an array of FieldBinding objects, All strings except for the last one have a comma at the end.



71
72
73
74
75
76
77
78
79
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 71

def routing_params_transcoder_field_binding_strings
  return [] if routing_params_with_regexes.empty?
  match_init_strings = routing_params_with_regexes.map do |name, regex, preserve_slashes|
    "Gapic::Rest::GrpcTranscoder::HttpBinding::FieldBinding" \
      ".new(\"#{name}\", %r{#{regex}}, #{preserve_slashes}),"
  end
  match_init_strings << match_init_strings.pop.chop # remove the trailing comma for the last element
  match_init_strings
end

#routing_params_transcoder_matches_stringsArray<String>

The strings to initialize the matches parameter when initializing a grpc transcoder binding. The matches parameter is an array of arrays, so every string here is in a ruby array syntax. All strings except for the last one have a comma at the end.



55
56
57
58
59
60
61
62
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 55

def routing_params_transcoder_matches_strings
  return [] if routing_params_with_regexes.empty?
  match_init_strings = routing_params_with_regexes.map do |name, regex, preserve_slashes|
    "[\"#{name}\", %r{#{regex}}, #{preserve_slashes}],"
  end
  match_init_strings << match_init_strings.pop.chop # remove the trailing comma for the last element
  match_init_strings
end

#uri_for_transcodingString

Performs a limited URI transcoding to create a string that will interpolate the values from the request object to create a request URI at runtime. Currently only supports "value" into "request_object.value"



38
39
40
41
42
43
44
45
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 38

def uri_for_transcoding
  return path unless routing_params?

  @binding.routing_params.reduce path do |uri, param|
    param_esc = Regexp.escape param
    uri.gsub(/{#{param_esc}[^}]*}/, "{#{param}}")
  end
end

#verbString



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body

#verb?Boolean



103
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103

def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body