Class: Gapic::Model::Mixins
- Inherits:
-
Object
- Object
- Gapic::Model::Mixins
- Defined in:
- lib/gapic/model/mixins.rb
Overview
Aggregated information about the mixin services that should be referenced from their gems in the generated client libraries
Defined Under Namespace
Classes: Mixin
Constant Summary collapse
- LRO_SERVICE =
LRO might be specified in the mixins but it is not generated as a mixin
"google.longrunning.Operations"
- LOCATIONS_SERVICE =
Locations and Iam are generated as mixins
"google.cloud.location.Locations"
- IAM_SERVICE =
"google.iam.v1.IAMPolicy"
Instance Attribute Summary collapse
-
#api_services ⇒ Enumerable<String>
List of services from the Api model.
Class Method Summary collapse
-
.mixin_message_field_address?(message_field_address, gem_name: nil) ⇒ boolean
Returns true if the given service address is a mixin.
-
.mixin_service_address?(service_address, gem_name: nil) ⇒ boolean
Returns true if the given service address is a mixin.
Instance Method Summary collapse
-
#dependencies ⇒ Hash<String, String>
Aggregated dependencies for the mix-in services.
-
#initialize(api_services, service_config, gem_name) ⇒ Mixins
constructor
A new instance of Mixins.
-
#mixin_services ⇒ Enumerable<String>
Full proto names of the mix-in services.
-
#mixins ⇒ Enumerable<Mixin>
List of Mixin objects, providing the information that is needed to add the mixin service references to the generated library.
-
#mixins? ⇒ Boolean
Whether there are any mix-in services.
Constructor Details
#initialize(api_services, service_config, gem_name) ⇒ Mixins
Returns a new instance of Mixins.
41 42 43 44 45 |
# File 'lib/gapic/model/mixins.rb', line 41 def initialize api_services, service_config, gem_name @api_services = api_services @service_config = service_config @gem_name = gem_name end |
Instance Attribute Details
#api_services ⇒ Enumerable<String>
Returns List of services from the Api model.
32 33 34 |
# File 'lib/gapic/model/mixins.rb', line 32 def api_services @api_services end |
Class Method Details
.mixin_message_field_address?(message_field_address, gem_name: nil) ⇒ boolean
Returns true if the given service address is a mixin.
This just checks the service against a (hard-coded) set of known mixins.
If gem_name
is provided, objects from the package of the service
that corresponds to that gem_name are not considered mixins.
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/gapic/model/mixins.rb', line 176 def self. , gem_name: nil = .join "." unless .is_a? String # NB: messages are checked against package, not service # The dot is added to the package name to ensure that e.g. `google.iam.v1` is not considered # a parent package to messages and fields within `google.iam.v1beta1` service_address = MIXIN_GEM_NAMES.keys.find do |sn| .start_with? "#{MIXIN_PACKAGE_NAMES[sn]}." end !service_address.nil? && gem_name != MIXIN_GEM_NAMES[service_address] end |
.mixin_service_address?(service_address, gem_name: nil) ⇒ boolean
Returns true if the given service address is a mixin.
This just checks the service against a (hard-coded) set of known mixins.
If gem_name
is provided, services that correspond to that gem_name are not considered mixins.
160 161 162 163 |
# File 'lib/gapic/model/mixins.rb', line 160 def self.mixin_service_address? service_address, gem_name: nil service_address = service_address.join "." unless service_address.is_a? String MIXIN_GEM_NAMES.include?(service_address) && gem_name != MIXIN_GEM_NAMES[service_address] end |
Instance Method Details
#dependencies ⇒ Hash<String, String>
Returns Aggregated dependencies for the mix-in services.
69 70 71 |
# File 'lib/gapic/model/mixins.rb', line 69 def dependencies @dependencies ||= mixins.reduce({}) { |deps, mixin| deps.merge mixin.dependency } end |
#mixin_services ⇒ Enumerable<String>
Returns Full proto names of the mix-in services.
60 61 62 63 64 65 |
# File 'lib/gapic/model/mixins.rb', line 60 def mixin_services @mixin_services ||= begin candidates = services_in_config & SERVICE_TO_DEPENDENCY.keys candidates.reject { |name| SERVICE_TO_DEPENDENCY[name].include? @gem_name } end end |
#mixins ⇒ Enumerable<Mixin>
Returns List of Mixin objects, providing the information that is needed to add the mixin service references to the generated library.
55 56 57 |
# File 'lib/gapic/model/mixins.rb', line 55 def mixins @mixins ||= mixin_services.map { |service| create_mixin service } end |
#mixins? ⇒ Boolean
Returns Whether there are any mix-in services.
48 49 50 |
# File 'lib/gapic/model/mixins.rb', line 48 def mixins? mixin_services.any? end |