Class: Gapic::Presenters::Method::HttpBindingPresenter
- Inherits:
-
Object
- Object
- Gapic::Presenters::Method::HttpBindingPresenter
- 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
-
#body ⇒ String
The
body
specified for this binding or an empty string if not specified. -
#body? ⇒ Boolean
Whether the binding has a
body
specified. -
#initialize(binding) ⇒ HttpBindingPresenter
constructor
A new instance of HttpBindingPresenter.
-
#path ⇒ String
A binding path or an empty string if not present.
-
#path? ⇒ Boolean
Whether a binding path is present and non-empty.
-
#routing_params? ⇒ Boolean
Whether any routing params are present for this bindings.
-
#routing_params_transcoder_field_binding_strings ⇒ Array<String>
The strings to initialize the
bindings
parameter when initializing a gapic http binding. -
#routing_params_transcoder_matches_strings ⇒ Array<String>
The strings to initialize the
matches
parameter when initializing a grpc transcoder binding. -
#uri_for_transcoding ⇒ String
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.
-
#verb ⇒ String
The http verb for this binding.
-
#verb? ⇒ Boolean
Whether a http verb is present for this binding.
Constructor Details
#initialize(binding) ⇒ HttpBindingPresenter
Returns a new instance of HttpBindingPresenter.
26 27 28 |
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 26 def initialize binding @binding = binding end |
Instance Method Details
#body ⇒ String
Returns The body
specified for this binding
or an empty string if not specified.
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
Returns Whether the binding has a body
specified.
103 |
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103 def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body |
#path ⇒ String
Returns A binding path or an empty string if not present.
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
Returns Whether a binding path is present and non-empty.
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
Returns Whether any routing params are present for this bindings.
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_strings ⇒ Array<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_strings ⇒ Array<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_transcoding ⇒ String
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 |
#verb ⇒ String
Returns The http verb for this binding.
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
Returns Whether a http verb is present for this binding.
103 |
# File 'lib/gapic/presenters/method/http_binding_presenter.rb', line 103 def_delegators :@binding, :verb?, :verb, :path?, :path, :routing_params?, :body?, :body |