-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes for v5 release. Updating library backend to new gapic layer. (#…
…219) Change-Id: I9dac4fc0645dfda3cbe30fca0d3cd834d837f2a2
- Loading branch information
Showing
6,119 changed files
with
373,646 additions
and
196,354 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "spec_helper" | ||
require "src/template_service" | ||
|
||
RSpec.describe TemplateService do | ||
subject(:service) { TemplateService.new(gapic_client_class, path) } | ||
|
||
let(:gapic_client_class) { | ||
double( | ||
:klass, | ||
name: "Google::Ads::GoogleAds::V2::Services::GoogleAdsService::Client", | ||
) | ||
} | ||
|
||
let(:path) { "in the real world this would be a file path" } | ||
|
||
describe "#factory_method_name" do | ||
it "correctly drops _service_client" do | ||
expect(service.factory_method_name).not_to include("_service_client") | ||
end | ||
end | ||
|
||
describe "#rpc_request_type_for" do | ||
let(:input) { double(:input_klass) } | ||
|
||
before do | ||
# require returns true, so let's just stub it here | ||
allow(service).to receive(:require).with(path).and_return(true) | ||
stub_const( | ||
"Google::Ads::GoogleAds::V2::Services::GoogleAdsService::Service", | ||
double( | ||
:fake_service_klass, | ||
rpc_descs: {Search: double(input: input)} | ||
) | ||
) | ||
end | ||
|
||
it "finds the right rpc type" do | ||
expect(service.rpc_request_type_for(:search)).to eq(input) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require 'src/filters' | ||
require "active_support" | ||
require "active_support/core_ext" | ||
|
||
class TemplateService | ||
attr_reader :path | ||
|
||
def initialize(klass, path) | ||
@klass = klass | ||
@path = cleanup_path(path, :SERVICE).freeze | ||
end | ||
|
||
def name | ||
klass.name.dup | ||
end | ||
|
||
def factory_method_name | ||
factory_name.gsub("ServiceClient", "").underscore | ||
end | ||
|
||
def is_suitable_for_template_at_verison?(version) | ||
return false if name.include?("Operations::Client") | ||
return true if name.start_with?("Google::Ads::GoogleAds::#{version}") | ||
|
||
false | ||
end | ||
|
||
def rpc_request_type_for(rpc) | ||
rpc_requests.select { |rpc_name| | ||
rpc_name == rpc | ||
}.values.first.input | ||
end | ||
|
||
def rpc_names | ||
rpc_requests.keys | ||
end | ||
|
||
private | ||
|
||
attr_reader :klass | ||
|
||
def rpc_requests | ||
# pnlpn@ was here on 2019-12-04: | ||
# rpc_descs is a hash with uppercased RPC names typed as symbols, e.g. | ||
# (:Search) so we underscore so that we're safe for ruby method names | ||
Hash[stub_class.rpc_descs.map { |desc, value| | ||
[desc.to_s.underscore.to_sym, value] | ||
}] | ||
end | ||
|
||
def factory_name | ||
name.split("::")[-2..-1].join("") | ||
end | ||
|
||
def stub_class | ||
# pnlpn@ was here on 2019-12-04: | ||
# the new Gapic service type doesn't cleanly expose the request type that | ||
# it needs the request to be, so this method gets it. | ||
|
||
# this stanza goes from the gax generated FooService::Client to | ||
# FooService::Service and requires it. | ||
stub_path = path.gsub("\/client.rb", "_services_pb.rb") | ||
require stub_path | ||
|
||
# drop "Client" off the end of the constant name, and require the "Service", | ||
# which is the stub class generated by the GRPC protoc compiler, this does | ||
# have enough information for us to recover the RPC information | ||
Kernel.const_get( | ||
name.split("::")[0...-1].join("::") + "::Service" | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.