Class: Gapic::Schema::Resource
- Inherits:
-
Object
- Object
- Gapic::Schema::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/gapic/schema/wrappers.rb
Overview
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 #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.
Instance Attribute Summary collapse
-
#descriptor ⇒ Array<Gapic::Schema::ResourceDescriptor>
readonly
The resource descriptor.
-
#parent ⇒ Gapic::Schema::File, Gapic::Schema::Message
The parent object.
-
#parent_resources ⇒ Array<Gapic::Schema::Resource>
readonly
Parent resources.
-
#parsed_parent_patterns ⇒ Object
readonly
Returns the value of attribute parsed_parent_patterns.
-
#parsed_patterns ⇒ Array<String>
readonly
The template form of the patterns.
Instance Method Summary collapse
-
#containing_api ⇒ Gapic::Schema::Api
Returns the "root" of this schema.
-
#containing_file ⇒ Gapic::Schema::File
Returns the file containing this proto entity.
-
#initialize(descriptor) ⇒ Resource
constructor
Initializes a resource object.
-
#name_field ⇒ String
The field on the resource that designates the resource name field.
-
#pattern ⇒ Array<String>
The set of patterns.
-
#type ⇒ String
The resource type string.
Constructor Details
#initialize(descriptor) ⇒ Resource
Initializes a resource object.
955 956 957 958 959 960 961 962 963 964 |
# File 'lib/gapic/schema/wrappers.rb', line 955 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 |
Instance Attribute Details
#descriptor ⇒ Array<Gapic::Schema::ResourceDescriptor> (readonly)
Returns The resource descriptor.
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/gapic/schema/wrappers.rb', line 942 class Resource extend Forwardable attr_reader :descriptor attr_reader :parsed_patterns attr_reader :parsed_parent_patterns attr_reader :parent_resources attr_accessor :parent # Initializes a resource object. # @param descriptor [Google::Api::ResourceDescriptor] the protobuf # representation of this resource. 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 # Returns the "root" of this schema. # @return [Gapic::Schema::Api] def containing_api parent&.containing_api end # Returns the file containing this proto entity # @return [Gapic::Schema::File] def containing_file parent&.containing_file end # @!method type # @return [String] the resource type string. # @!method pattern # @return [Array<String>] the set of patterns. # @!method name_field # @return [String] the field on the resource that designates the # resource name field. If omitted, this is assumed to be "name". def_delegators( :descriptor, :type, :pattern, :name_field ) end |
#parent ⇒ Gapic::Schema::File, Gapic::Schema::Message
Returns The parent object.
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/gapic/schema/wrappers.rb', line 942 class Resource extend Forwardable attr_reader :descriptor attr_reader :parsed_patterns attr_reader :parsed_parent_patterns attr_reader :parent_resources attr_accessor :parent # Initializes a resource object. # @param descriptor [Google::Api::ResourceDescriptor] the protobuf # representation of this resource. 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 # Returns the "root" of this schema. # @return [Gapic::Schema::Api] def containing_api parent&.containing_api end # Returns the file containing this proto entity # @return [Gapic::Schema::File] def containing_file parent&.containing_file end # @!method type # @return [String] the resource type string. # @!method pattern # @return [Array<String>] the set of patterns. # @!method name_field # @return [String] the field on the resource that designates the # resource name field. If omitted, this is assumed to be "name". def_delegators( :descriptor, :type, :pattern, :name_field ) end |
#parent_resources ⇒ Array<Gapic::Schema::Resource> (readonly)
Returns Parent resources.
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/gapic/schema/wrappers.rb', line 942 class Resource extend Forwardable attr_reader :descriptor attr_reader :parsed_patterns attr_reader :parsed_parent_patterns attr_reader :parent_resources attr_accessor :parent # Initializes a resource object. # @param descriptor [Google::Api::ResourceDescriptor] the protobuf # representation of this resource. 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 # Returns the "root" of this schema. # @return [Gapic::Schema::Api] def containing_api parent&.containing_api end # Returns the file containing this proto entity # @return [Gapic::Schema::File] def containing_file parent&.containing_file end # @!method type # @return [String] the resource type string. # @!method pattern # @return [Array<String>] the set of patterns. # @!method name_field # @return [String] the field on the resource that designates the # resource name field. If omitted, this is assumed to be "name". def_delegators( :descriptor, :type, :pattern, :name_field ) end |
#parsed_parent_patterns ⇒ Object (readonly)
Returns the value of attribute parsed_parent_patterns.
947 948 949 |
# File 'lib/gapic/schema/wrappers.rb', line 947 def parsed_parent_patterns @parsed_parent_patterns end |
#parsed_patterns ⇒ Array<String> (readonly)
Returns 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/*"].
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/gapic/schema/wrappers.rb', line 942 class Resource extend Forwardable attr_reader :descriptor attr_reader :parsed_patterns attr_reader :parsed_parent_patterns attr_reader :parent_resources attr_accessor :parent # Initializes a resource object. # @param descriptor [Google::Api::ResourceDescriptor] the protobuf # representation of this resource. 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 # Returns the "root" of this schema. # @return [Gapic::Schema::Api] def containing_api parent&.containing_api end # Returns the file containing this proto entity # @return [Gapic::Schema::File] def containing_file parent&.containing_file end # @!method type # @return [String] the resource type string. # @!method pattern # @return [Array<String>] the set of patterns. # @!method name_field # @return [String] the field on the resource that designates the # resource name field. If omitted, this is assumed to be "name". def_delegators( :descriptor, :type, :pattern, :name_field ) end |
Instance Method Details
#containing_api ⇒ Gapic::Schema::Api
Returns the "root" of this schema.
968 969 970 |
# File 'lib/gapic/schema/wrappers.rb', line 968 def containing_api parent&.containing_api end |
#containing_file ⇒ Gapic::Schema::File
Returns the file containing this proto entity
974 975 976 |
# File 'lib/gapic/schema/wrappers.rb', line 974 def containing_file parent&.containing_file end |
#name_field ⇒ String
Returns the field on the resource that designates the resource name field. If omitted, this is assumed to be "name".
985 986 987 988 989 990 |
# File 'lib/gapic/schema/wrappers.rb', line 985 def_delegators( :descriptor, :type, :pattern, :name_field ) |
#pattern ⇒ Array<String>
Returns the set of patterns.
985 986 987 988 989 990 |
# File 'lib/gapic/schema/wrappers.rb', line 985 def_delegators( :descriptor, :type, :pattern, :name_field ) |
#type ⇒ String
Returns the resource type string.
985 986 987 988 989 990 |
# File 'lib/gapic/schema/wrappers.rb', line 985 def_delegators( :descriptor, :type, :pattern, :name_field ) |