Class: Google::Ads::GoogleAds::ServiceWrapper
- Inherits:
-
Object
- Object
- Google::Ads::GoogleAds::ServiceWrapper
- Defined in:
- lib/google/ads/google_ads/service_wrapper.rb
Instance Method Summary collapse
- #configure(&block) ⇒ Object
-
#initialize(service:, rpc_inputs:, deprecation:) ⇒ ServiceWrapper
constructor
A new instance of ServiceWrapper.
- #method_missing(name, *args, **kwargs, &blk) ⇒ Object
- #respond_to_missing?(m, include_private = false) ⇒ Boolean
Constructor Details
#initialize(service:, rpc_inputs:, deprecation:) ⇒ ServiceWrapper
Returns a new instance of ServiceWrapper.
12 13 14 15 16 |
# File 'lib/google/ads/google_ads/service_wrapper.rb', line 12 def initialize(service:, rpc_inputs:, deprecation:) @service = service @rpc_inputs = rpc_inputs @deprecation = deprecation end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &blk) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/google/ads/google_ads/service_wrapper.rb', line 26 def method_missing(name, *args, **kwargs, &blk) # delegate with no request manipulation if the method isn't an # rpc, so that we don't elide any of the configuration or other # methods available on the gax clients unless rpc_inputs.include?(name) return service.public_send(name, *args, **kwargs, &blk) end rpc_input_class = rpc_inputs.fetch(name) request = rpc_input_class.new if kwargs.include?(:request) || kwargs.include?(:options) = kwargs.delete(:options) kwargs.fetch(:request, {}).each do |name, value| write_field(request, value, name) end service.public_send(name, request, ) elsif !kwargs.empty? && args.empty? kwargs.each do |name, value| write_field(request, value, name) end service.public_send(name, request, nil) elsif args.empty? # no args specified at all, just pass through service.public_send(name, request, nil) else # this branch is the legacy version, which is no longer supported # zip will fill with nils by default, so we truncate the number # of fields we set to match the argument length here. args_and_fields = args.zip( request_positional_args(rpc_input_class)[0...args.length] ) field_names = [] args_and_fields.each do |(arg, field)| field_names << field.name end service_name_segments = service.class.name.split("::") service_name = GoogleAds::Utils.underscore( service_name_segments[service_name_segments.length-2] ) method_name = "#{service_name}.#{name}" raise ArgumentError, "Calling #{method_name} with positional " \ "arguments is deprecated, please update it to use kwargs, e.g.: " \ "#{method_name}" \ "(#{field_names.map { |fn| "#{fn}: ..."}.join(", ")})" end end |
Instance Method Details
#configure(&block) ⇒ Object
18 19 20 |
# File 'lib/google/ads/google_ads/service_wrapper.rb', line 18 def configure(&block) @service.configure(&block) end |
#respond_to_missing?(m, include_private = false) ⇒ Boolean
22 23 24 |
# File 'lib/google/ads/google_ads/service_wrapper.rb', line 22 def respond_to_missing?(m, include_private=false) service.respond_to?(m, include_private) end |