Module: Gapic::UriTemplate::Parser

Defined in:
lib/gapic/uri_template/parser.rb

Overview

A URI template parser. see https://tools.ietf.org/html/rfc6570 URI Template

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#path_patternString (readonly)

Returns The path pattern to be parsed.

Returns:

  • (String)

    The path pattern to be parsed.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gapic/uri_template/parser.rb', line 26

module Parser
  # @private
  # `/(?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?}/`
  URI_TEMPLATE = %r{
    (?<positional>\*\*?)
    |
    {(?<name>[^/]+?)(?:=(?<template>.+?))?}
  }x.freeze

  def self.parse_arguments uri_template
    arguments = []

    while (match = URI_TEMPLATE.match uri_template)
      # The String before the match needs to be added to the segments
      arguments << match[:name] if match[:name]
      uri_template = match.post_match
    end

    arguments
  end
end

#segmentsArray<Segment|String> (readonly)

Returns The segments of the parsed path pattern.

Returns:

  • (Array<Segment|String>)

    The segments of the parsed path pattern.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gapic/uri_template/parser.rb', line 26

module Parser
  # @private
  # `/(?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?}/`
  URI_TEMPLATE = %r{
    (?<positional>\*\*?)
    |
    {(?<name>[^/]+?)(?:=(?<template>.+?))?}
  }x.freeze

  def self.parse_arguments uri_template
    arguments = []

    while (match = URI_TEMPLATE.match uri_template)
      # The String before the match needs to be added to the segments
      arguments << match[:name] if match[:name]
      uri_template = match.post_match
    end

    arguments
  end
end

Class Method Details

.parse_arguments(uri_template) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gapic/uri_template/parser.rb', line 35

def self.parse_arguments uri_template
  arguments = []

  while (match = URI_TEMPLATE.match uri_template)
    # The String before the match needs to be added to the segments
    arguments << match[:name] if match[:name]
    uri_template = match.post_match
  end

  arguments
end