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:

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

descriptor[R]
parent[RW]
parent_resources[R]
parsed_parent_patterns[R]
parsed_patterns[R]

Public Class Methods

new(descriptor) click to toggle source

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

containing_api() click to toggle source

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
containing_file() click to toggle source

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