Class: Gapic::Model::Mixins

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_services, service_config, gem_name) ⇒ Mixins

Returns a new instance of Mixins.

Parameters:

  • api_services (Enumerable<String>)

    List of services from the Api model

  • service_config (Google::Api::Service)

    The service config

  • gem_name (String)

    The name of the gem.



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_servicesEnumerable<String>

Returns List of services from the Api model.

Returns:

  • (Enumerable<String>)

    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.

Parameters:

  • message_field_address (String, Array<String>)

    The address (either array or dot-delimited) of the message or field to check.

  • gem_name (String) (defaults to: nil)

    The name of the gem.

Returns:

  • (boolean)


176
177
178
179
180
181
182
183
184
185
186
# File 'lib/gapic/model/mixins.rb', line 176

def self.mixin_message_field_address? message_field_address, gem_name: nil
  message_field_address = message_field_address.join "." unless message_field_address.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|
    message_field_address.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.

Parameters:

  • service_address (String, Array<String>)

    The address (either array or dot-delimited) of the service to check.

  • gem_name (String) (defaults to: nil)

    The name of the gem.

Returns:

  • (boolean)


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

#dependenciesHash<String, String>

Returns Aggregated dependencies for the mix-in services.

Returns:

  • (Hash<String, String>)

    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_servicesEnumerable<String>

Returns Full proto names of the mix-in services.

Returns:

  • (Enumerable<String>)

    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

#mixinsEnumerable<Mixin>

Returns List of Mixin objects, providing the information that is needed to add the mixin service references to the generated library.

Returns:

  • (Enumerable<Mixin>)

    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.

Returns:

  • (Boolean)

    Whether there are any mix-in services



48
49
50
# File 'lib/gapic/model/mixins.rb', line 48

def mixins?
  mixin_services.any?
end