gapic-generator/lib/gapic/schema/api.rb
# Does a pre-analysis of all resources defined in the job. This has
# two effects:
# * Side effect: each resource has its parent_resources field set.
# * A mapping from resource type to resource wrapper is returned.
Does a pre-analysis of all resources defined in the job. This has
two effects:
Side effect: each resource has its parent_resources field set.
A mapping from resource type to resource wrapper is returned.
Does a pre - analysis of all resources defined in the job . This has two effects : Side effect : each resource has its parent_resources field set . A mapping from resource type to resource wrapper is returned .
def analyze_resources
        types = {}
        patterns = {}
        @files.each do |file|
          file.resources.each { |resource| populate_resource_lookups resource, types, patterns }
          file.messages.each { |message| populate_message_resource_lookups message, types, patterns }
        end
        types.each do |_type, resource|
          parents = resource.parsed_parent_patterns
                            .flat_map { |pat| Array(patterns[pat]) }
                            .uniq
          resource.parent_resources.replace parents
        end
        types
      end
def analyze_resources types = { } patterns = { } @files . each do | file | file . resources . each { | resource | populate_resource_lookups resource , types , patterns } file . messages . each { | message | populate_message_resource_lookups message , types , patterns } end types . each do | _type , resource | parents = resource . parsed_parent_patterns . flat_map { | pat | Array ( patterns [ pat ] ) } . uniq resource . parent_resources . replace parents end types end
Does a pre-analysis of all resources defined in the job.
Does a pre - analysis of all resources defined in the job .
# In order to set parent_resources, we first populate a mapping from # parsed pattern to resources that use it (in the patterns variable). # Note that there may be multiple resources associated with a pattern. # (This is uncommon, but one example is monitoring v3 which uses # "projects/*" for its workspace type as well as inheriting the common # project type. We thus map each pattern to an array of resources.) # Constructing the patterns mapping is done in one pass along with # populating the type mapping (which maps only to single resources.) # Then, we go through all resources again, get each's expected parent # patterns, and anything that shows up in the patterns mapping is taken # to be a parent.