Sha256: 10e8a1c596fa99daed68273a28d1339ff7238e3c5deacabc0feca3ea17466a9e

Contents?: true

Size: 1.52 KB

Versions: 15

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module Gapic
  module UriTemplate
    # A URI template parser.
    # see https://tools.ietf.org/html/rfc6570 URI Template
    #
    # @!attribute [r] path_pattern
    #   @return [String] The path pattern to be parsed.
    # @!attribute [r] segments
    #   @return [Array<Segment|String>] The segments of the parsed path pattern.
    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
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gapic-generator-0.6.15 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.14 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.13 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.12 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.11 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.10 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.9 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.8 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.7 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.6 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.5 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.4 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.3 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.2 lib/gapic/uri_template/parser.rb
gapic-generator-0.6.1 lib/gapic/uri_template/parser.rb