class Gapic::Schema::Resource
Wrapper for a protobuf Resource
.
Unlike most wrappers, this does not subclass the {Proto} wrapper because it does not use the fields exposed by that wrapper (`address`, `docs`, etc.) This is here principally to augment the resource definition with information about resource parent-child relationships.
Resource
parentage is defined implicitly by path patterns. The algorithm is as follows:
-
If the final segment of a pattern is an ID segment (i.e. `*` or some `{name}`) then remove it and the previous segment (which we assume to be the corresponding collection identifier, as described in AIP-122.) The resulting pattern is what we expect a parent to have.
-
If the final segment is static, then assume the pattern represents a singleton resource (AIP-156) and remove only that one segment. The resulting pattern is what we expect a parent to have.
The {Resource#parsed_parent_patterns} method returns the set of patterns we expect of parents. It is then possible to search for resources with those patterns to determine what the parents are.
@!attribute [rw] parent
@return [Gapic::Schema::File,Gapic::Schema::Message] The parent object.
@!attribute [r] descriptor
@return [Array<Gapic::Schema::ResourceDescriptor>] The resource descriptor.
@!attribute [r] parsed_patterns
@return [Array<String>] The template form of the patterns. Template means all ID segments are replaced by asterisks to remove non-structural differences due to different names being used. For example, if a pattern is `"projects/{project}""`, the corresponding parsed pattern would be `"projects/*"]`.
@!attribure [r] parsed_parent_patterns
return [Array<String>] Parsed patterns for the expected parents.
@!attribute [r] parent_resources
@return [Array<Gapic::Schema::Resource>] Parent resources
Attributes
Public Class Methods
Initializes a resource object. @param descriptor [Google::Api::ResourceDescriptor] the protobuf
representation of this resource.
# File lib/gapic/schema/wrappers.rb, line 832 def initialize descriptor @parent = nil @descriptor = descriptor patterns = descriptor.pattern.map do |pattern| Gapic::PathPattern.parse pattern end.freeze @parsed_patterns = patterns.map(&:template).compact.uniq.freeze @parsed_parent_patterns = patterns.map(&:parent_template).compact.uniq.freeze @parent_resources = [] end
Public Instance Methods
Returns the “root” of this schema. @return [Gapic::Schema::Api]
# File lib/gapic/schema/wrappers.rb, line 845 def containing_api parent&.containing_api end
Returns the file containing this proto entity @return [Gapic::Schema::File]
# File lib/gapic/schema/wrappers.rb, line 851 def containing_file parent&.containing_file end