class Gapic::PathPattern::ResourceIdSegment

A ResourceId segment in a path pattern.

ResourceId segments can be simple, with one resource name
or complex, with multiple resource names divided by separators

@!attribure [r] type

@return [String] The type of this segment

@!attribute [r] pattern

@return [String] The pattern of the segment, for the positional segment it is also
  a pattern of its resource

@!attribute [r] resource_names

@return [Array<String>] The resource names in this segment

@!attribute [r] resource_patterns

@return [Array<String>] The resource patterns associated with
  the resource_names of this segment

Attributes

pattern[R]
resource_names[R]
resource_patterns[R]
type[R]

Public Class Methods

create_simple(name) click to toggle source

Initialization helper to create a simple resource without a pattern @param name [String] resource name @return [ResourceIdSegment]

# File lib/gapic/path_pattern/segment.rb, line 201
def self.create_simple name
  ResourceIdSegment.new :simple_resource_id, "{#{name}}", [name]
end
new(type, pattern, resource_names, resource_patterns = []) click to toggle source
# File lib/gapic/path_pattern/segment.rb, line 128
def initialize type, pattern, resource_names, resource_patterns = []
  @type              = type
  @pattern           = pattern
  @resource_names    = resource_names
  @resource_patterns = resource_patterns
end

Public Instance Methods

==(other) click to toggle source

@private

# File lib/gapic/path_pattern/segment.rb, line 206
def == other
  return false unless other.is_a? self.class

  (type == other.type && pattern == other.pattern &&
    resource_names == other.resource_names &&
    resource_patterns == other.resource_patterns)
end
arguments() click to toggle source

Names of the segment's arguments @return [Array<String>]

# File lib/gapic/path_pattern/segment.rb, line 166
def arguments
  resource_names
end
expected_path_for_dummy_values(start_index) click to toggle source

Returns a segment's pattern filled with dummy values

names of the values are generated starting from the index provided

@param start_index [Integer] a starting index for dummy value generation @return [String] a pattern filled with dummy values

# File lib/gapic/path_pattern/segment.rb, line 175
def expected_path_for_dummy_values start_index
  return "value#{start_index}" if type == :simple_resource_id

  resource_names.each_with_index.reduce pattern do |exp_path, (res_name, index)|
    exp_path.sub "{#{res_name}}", "value#{start_index + index}"
  end
end
nontrivial_resource_pattern?() click to toggle source

Whether the segment provides a nontrivial resource pattern @return [Boolean]

# File lib/gapic/path_pattern/segment.rb, line 152
def nontrivial_resource_pattern?
  resource_patterns.any? { |res_pattern| !res_pattern.match?(/^\*+$/) }
end
path_string() click to toggle source

Path string for this segment @return [String]

# File lib/gapic/path_pattern/segment.rb, line 186
def path_string
  type == :simple_resource_id ? "\#{#{resource_names[0]}}" : pattern.gsub("{", "\#{")
end
pattern_template() click to toggle source

A pattern template for this segment @return [String]

# File lib/gapic/path_pattern/segment.rb, line 193
def pattern_template
  "*"
end
positional?() click to toggle source

Whether the segment is positional @return [Boolean]

# File lib/gapic/path_pattern/segment.rb, line 138
def positional?
  false
end
provides_arguments?() click to toggle source

Whether the segment provides arguments @return [Boolean]

# File lib/gapic/path_pattern/segment.rb, line 159
def provides_arguments?
  true
end
resource_pattern?() click to toggle source

Whether the segment provides a resource pattern @return [Boolean]

# File lib/gapic/path_pattern/segment.rb, line 145
def resource_pattern?
  resource_patterns.any?
end