gapic-generator 0.4.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/lib/gapic/file_formatter.rb +0 -1
- data/lib/gapic/formatting_utils.rb +6 -6
- data/lib/gapic/generator/version.rb +1 -1
- data/lib/gapic/generators/default_generator.rb +16 -14
- data/lib/gapic/helpers/filepath_helper.rb +1 -0
- data/lib/gapic/helpers/namespace_helper.rb +8 -1
- data/lib/gapic/{path_template.rb → path_pattern.rb} +9 -8
- data/lib/gapic/path_pattern/parser.rb +146 -0
- data/lib/gapic/path_pattern/pattern.rb +80 -0
- data/lib/gapic/path_pattern/segment.rb +276 -0
- data/lib/gapic/presenters/field_presenter.rb +9 -9
- data/lib/gapic/presenters/file_presenter.rb +1 -1
- data/lib/gapic/presenters/gem_presenter.rb +39 -3
- data/lib/gapic/presenters/method_presenter.rb +19 -19
- data/lib/gapic/presenters/package_presenter.rb +4 -3
- data/lib/gapic/presenters/resource_presenter.rb +48 -36
- data/lib/gapic/presenters/service_presenter.rb +20 -14
- data/lib/gapic/schema/api.rb +7 -0
- data/lib/gapic/schema/wrappers.rb +13 -19
- data/lib/gapic/uri_template.rb +36 -0
- data/lib/gapic/uri_template/parser.rb +50 -0
- data/templates/default/gem/gemfile.erb +3 -0
- data/templates/default/gem/gemspec.erb +7 -6
- data/templates/default/gem/rakefile.erb +1 -0
- data/templates/default/gem/test_helper.erb +8 -0
- data/templates/default/layouts/_ruby.erb +5 -4
- data/templates/default/lib/_service.erb +2 -0
- data/templates/default/proto_docs/_message.erb +2 -2
- data/templates/default/service/client/_client.erb +7 -4
- data/templates/default/service/client/_config.erb +33 -29
- data/templates/default/service/client/_credentials.erb +1 -1
- data/templates/default/service/client/_operations.erb +3 -1
- data/templates/default/service/client/method/def/_options_defaults.erb +2 -2
- data/templates/default/service/client/method/def/_request_normal.erb +2 -2
- data/templates/default/service/client/method/def/_request_streaming.erb +3 -3
- data/templates/default/service/client/method/def/_response_normal.erb +1 -1
- data/templates/default/service/client/method/def/_response_paged.erb +2 -2
- data/templates/default/service/client/method/docs/_error.erb +1 -1
- data/templates/default/service/client/method/docs/_request_normal.erb +2 -2
- data/templates/default/service/client/method/docs/_request_streaming.erb +2 -2
- data/templates/default/service/client/method/docs/_response.erb +1 -1
- data/templates/default/service/client/resource/_def.erb +1 -1
- data/templates/default/service/client/resource/_doc.erb +1 -1
- data/templates/default/service/client/resource/_multi.erb +4 -7
- data/templates/default/service/client/resource/_single.erb +2 -3
- data/templates/default/service/test/_resource.erb +16 -0
- data/templates/default/service/test/client.erb +2 -5
- data/templates/default/service/test/client_operations.erb +2 -5
- data/templates/default/service/test/client_paths.erb +15 -0
- metadata +12 -6
- data/lib/gapic/path_template/parser.rb +0 -83
- data/lib/gapic/path_template/segment.rb +0 -67
@@ -64,8 +64,10 @@ class <%= service.operations_name %>
|
|
64
64
|
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
65
65
|
credentials = Credentials.new credentials, scope: @config.scope
|
66
66
|
end
|
67
|
+
@quota_project_id = @config.quota_project
|
68
|
+
@quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
|
67
69
|
|
68
|
-
@<%= service.lro_service.stub_name %> = Gapic::ServiceStub.new(
|
70
|
+
@<%= service.lro_service.stub_name %> = ::Gapic::ServiceStub.new(
|
69
71
|
<%= service.lro_service.proto_service_stub_name_full %>,
|
70
72
|
credentials: credentials,
|
71
73
|
endpoint: @config.endpoint,
|
@@ -1,12 +1,12 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
2
|
# Converts hash and nil to an options object
|
3
|
-
options = Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
|
3
|
+
options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
|
4
4
|
|
5
5
|
# Customize the options with defaults
|
6
6
|
metadata = @config.rpcs.<%= method.name %>.metadata.to_h
|
7
7
|
|
8
8
|
# Set x-goog-api-client and x-goog-user-project headers
|
9
|
-
metadata[:"x-goog-api-client"] ||= Gapic::Headers.x_goog_api_client \
|
9
|
+
metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
|
10
10
|
lib_name: @config.lib_name, lib_version: @config.lib_version,
|
11
11
|
gapic_version: ::<%= method.service.gem.version_name_full %>
|
12
12
|
metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
|
-
raise ArgumentError, "request must be provided" if request.nil?
|
2
|
+
raise ::ArgumentError, "request must be provided" if request.nil?
|
3
3
|
|
4
|
-
request = Gapic::Protobuf.coerce request, to: <%= method.request_type %>
|
4
|
+
request = ::Gapic::Protobuf.coerce request, to: <%= method.request_type %>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
|
-
unless request.is_a? Enumerable
|
3
|
-
raise ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
|
2
|
+
unless request.is_a? ::Enumerable
|
3
|
+
raise ::ArgumentError, "request must be an Enumerable" unless request.respond_to? :to_enum
|
4
4
|
request = request.to_enum
|
5
5
|
end
|
6
6
|
|
7
7
|
request = request.lazy.map do |req|
|
8
|
-
Gapic::Protobuf.coerce req, to: <%= method.request_type %>
|
8
|
+
::Gapic::Protobuf.coerce req, to: <%= method.request_type %>
|
9
9
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
2
|
@<%= method.service.stub_name %>.call_rpc :<%= method.name %>, request, options: options do |response, operation|
|
3
3
|
<%- if method.lro? -%>
|
4
|
-
response = Gapic::Operation.new response, <%= method.service.lro_client_ivar %>, options: options
|
4
|
+
response = ::Gapic::Operation.new response, <%= method.service.lro_client_ivar %>, options: options
|
5
5
|
<%- end -%>
|
6
6
|
yield response, operation if block_given?
|
7
7
|
return response
|
@@ -1,9 +1,9 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
2
|
@<%= method.service.stub_name %>.call_rpc :<%= method.name %>, request, options: options do |response, operation|
|
3
3
|
<%- if method.lro? -%>
|
4
|
-
wrap_lro_operation = ->(op_response) { Gapic::Operation.new op_response, <%= method.service.lro_client_ivar %> }
|
4
|
+
wrap_lro_operation = ->(op_response) { ::Gapic::Operation.new op_response, <%= method.service.lro_client_ivar %> }
|
5
5
|
<%- end -%>
|
6
|
-
response = Gapic::PagedEnumerable.new @<%= method.service.stub_name %>, :<%= method.name %>, request, response, operation, options<%- if method.lro? -%>, format_resource: wrap_lro_operation<%- end -%>
|
6
|
+
response = ::Gapic::PagedEnumerable.new @<%= method.service.stub_name %>, :<%= method.name %>, request, response, operation, options<%- if method.lro? -%>, format_resource: wrap_lro_operation<%- end -%>
|
7
7
|
yield response, operation if block_given?
|
8
8
|
return response
|
9
9
|
end
|
@@ -1,2 +1,2 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
|
-
# @raise [GRPC::BadStatus] if the RPC is aborted.
|
2
|
+
# @raise [::GRPC::BadStatus] if the RPC is aborted.
|
@@ -3,10 +3,10 @@
|
|
3
3
|
# Pass arguments to `<%= method.name %>` via a request object, either of type
|
4
4
|
# {<%= method.request_type %>} or an equivalent Hash.
|
5
5
|
#
|
6
|
-
# @param request [<%= method.request_type %>, Hash]
|
6
|
+
# @param request [<%= method.request_type %>, ::Hash]
|
7
7
|
# A request object representing the call parameters. Required. To specify no
|
8
8
|
# parameters, or to keep all the default parameter values, pass an empty Hash.
|
9
|
-
# @param options [Gapic::CallOptions, Hash]
|
9
|
+
# @param options [::Gapic::CallOptions, ::Hash]
|
10
10
|
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
|
11
11
|
<%-if method.arguments.any?-%>
|
12
12
|
#
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
|
-
# @param request [Gapic::StreamInput, Enumerable<<%= method.request_type %>, Hash>]
|
2
|
+
# @param request [::Gapic::StreamInput, ::Enumerable<<%= method.request_type %>, ::Hash>]
|
3
3
|
# An enumerable of {<%= method.request_type %>} instances.
|
4
|
-
# @param options [Gapic::CallOptions, Hash]
|
4
|
+
# @param options [::Gapic::CallOptions, ::Hash]
|
5
5
|
# Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%- assert_locals method -%>
|
2
2
|
# @yield [response, operation] Access the result along with the RPC operation
|
3
3
|
# @yieldparam response [<%= method.doc_response_type %>]
|
4
|
-
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
4
|
+
# @yieldparam operation [::GRPC::ActiveCall::Operation]
|
5
5
|
#
|
6
6
|
# @return [<%= method.doc_response_type %>]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<%- assert_locals pattern -%>
|
2
2
|
<%- pattern.arguments[0...-1].each do |arg| -%>
|
3
|
-
raise ArgumentError, "<%= arg %> cannot contain /" if <%= arg %>.to_s.include? "/"
|
3
|
+
raise ::ArgumentError, "<%= arg %> cannot contain /" if <%= arg %>.to_s.include? "/"
|
4
4
|
<%- end -%>
|
5
5
|
|
6
6
|
"<%= pattern.path_string %>"
|
@@ -3,26 +3,23 @@
|
|
3
3
|
# Create a fully-qualified <%= resource.name %> resource string.
|
4
4
|
#
|
5
5
|
<%- resource.patterns.each do |pattern| -%>
|
6
|
-
|
7
|
-
# @overload <%= resource.path_helper %>(<%= args_doc_sig %>)
|
6
|
+
# @overload <%= resource.path_helper %>(<%= pattern.formal_arguments %>)
|
8
7
|
<%= indent render(partial: "service/client/resource/doc", locals: { pattern: pattern }), "# " %>
|
9
8
|
#
|
10
9
|
<%- end -%>
|
11
|
-
# @return [String]
|
10
|
+
# @return [::String]
|
12
11
|
def <%= resource.path_helper %> **args
|
13
12
|
resources = {
|
14
13
|
<%- last_pattern_index = resource.patterns.count - 1 -%>
|
15
14
|
<%- resource.patterns.each_with_index do |pattern, index| -%>
|
16
15
|
<%- comma = last_pattern_index == index ? "" : "," -%>
|
17
|
-
|
18
|
-
<%- args_sig = pattern.arguments.map { |arg| "#{arg}:" }.join ", " -%>
|
19
|
-
<%= args_key %> => (proc do |<%= args_sig %>|
|
16
|
+
<%= pattern.arguments_key.inspect %> => (proc do |<%= pattern.formal_arguments %>|
|
20
17
|
<%= indent render(partial: "service/client/resource/def", locals: { pattern: pattern }), 6 %>
|
21
18
|
end)<%= comma %>
|
22
19
|
<%- end -%>
|
23
20
|
}
|
24
21
|
|
25
22
|
resource = resources[args.keys.sort.join(":")]
|
26
|
-
raise ArgumentError, "no resource found for values #{args.keys}" if resource.nil?
|
23
|
+
raise ::ArgumentError, "no resource found for values #{args.keys}" if resource.nil?
|
27
24
|
resource.call(**args)
|
28
25
|
end
|
@@ -4,8 +4,7 @@
|
|
4
4
|
#
|
5
5
|
<%= indent render(partial: "service/client/resource/doc", locals: { pattern: resource.patterns.first }), "# " %>
|
6
6
|
#
|
7
|
-
# @return [String]
|
8
|
-
|
9
|
-
def <%= resource.path_helper %> <%= args %>
|
7
|
+
# @return [::String]
|
8
|
+
def <%= resource.path_helper %> <%= resource.patterns.first.formal_arguments %>
|
10
9
|
<%= indent render(partial: "service/client/resource/def", locals: { pattern: resource.patterns.first }), 2 %>
|
11
10
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<%- assert_locals resource -%>
|
2
|
+
<%- assert_locals service -%>
|
3
|
+
<%- full_client_name = defined?(client_name_full) ? client_name_full : service.client_name_full -%>
|
4
|
+
def test_<%= resource.path_helper%>
|
5
|
+
grpc_channel = ::GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
|
6
|
+
::Gapic::ServiceStub.stub :new, nil do
|
7
|
+
client = <%= full_client_name %>.new do |config|
|
8
|
+
config.credentials = grpc_channel
|
9
|
+
end
|
10
|
+
<%- resource.patterns.each do |pattern| -%>
|
11
|
+
|
12
|
+
path = client.<%= resource.path_helper%> <%= pattern.arguments_with_dummy_values %>
|
13
|
+
assert_equal <%= pattern.expected_path_for_dummy_values.inspect %>, path
|
14
|
+
<%- end -%>
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%- assert_locals service -%>
|
2
|
+
<%= render partial: "shared/header" %>
|
3
|
+
require "helper"
|
4
|
+
|
5
|
+
require "gapic/grpc/service_stub"
|
6
|
+
|
7
|
+
require "<%= service.service_require %>"
|
8
|
+
|
9
|
+
class <%= service.client_name_full %>PathsTest < Minitest::Test
|
10
|
+
<%- service.references.each do |resource| -%>
|
11
|
+
<%= indent render(partial: "service/test/resource",
|
12
|
+
locals: { resource: resource, service: service }), 2 %>
|
13
|
+
|
14
|
+
<%- end %>
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gapic-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernest Landrito
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -217,9 +217,10 @@ files:
|
|
217
217
|
- lib/gapic/grpc_service_config/service_config.rb
|
218
218
|
- lib/gapic/helpers/filepath_helper.rb
|
219
219
|
- lib/gapic/helpers/namespace_helper.rb
|
220
|
-
- lib/gapic/
|
221
|
-
- lib/gapic/
|
222
|
-
- lib/gapic/
|
220
|
+
- lib/gapic/path_pattern.rb
|
221
|
+
- lib/gapic/path_pattern/parser.rb
|
222
|
+
- lib/gapic/path_pattern/pattern.rb
|
223
|
+
- lib/gapic/path_pattern/segment.rb
|
223
224
|
- lib/gapic/presenters.rb
|
224
225
|
- lib/gapic/presenters/enum_presenter.rb
|
225
226
|
- lib/gapic/presenters/enum_value_presenter.rb
|
@@ -239,6 +240,8 @@ files:
|
|
239
240
|
- lib/gapic/schema/api.rb
|
240
241
|
- lib/gapic/schema/loader.rb
|
241
242
|
- lib/gapic/schema/wrappers.rb
|
243
|
+
- lib/gapic/uri_template.rb
|
244
|
+
- lib/gapic/uri_template/parser.rb
|
242
245
|
- lib/google/api/annotations.pb.rb
|
243
246
|
- lib/google/api/client.pb.rb
|
244
247
|
- lib/google/api/field_behavior.pb.rb
|
@@ -260,6 +263,7 @@ files:
|
|
260
263
|
- templates/default/gem/rakefile.erb
|
261
264
|
- templates/default/gem/readme.erb
|
262
265
|
- templates/default/gem/rubocop.erb
|
266
|
+
- templates/default/gem/test_helper.erb
|
263
267
|
- templates/default/gem/version.erb
|
264
268
|
- templates/default/gem/yardopts.erb
|
265
269
|
- templates/default/helpers/default_helper.rb
|
@@ -319,8 +323,10 @@ files:
|
|
319
323
|
- templates/default/service/credentials.erb
|
320
324
|
- templates/default/service/operations.erb
|
321
325
|
- templates/default/service/paths.erb
|
326
|
+
- templates/default/service/test/_resource.erb
|
322
327
|
- templates/default/service/test/client.erb
|
323
328
|
- templates/default/service/test/client_operations.erb
|
329
|
+
- templates/default/service/test/client_paths.erb
|
324
330
|
- templates/default/service/test/method/_assert_response.erb
|
325
331
|
- templates/default/service/test/method/_bidi.erb
|
326
332
|
- templates/default/service/test/method/_client.erb
|
@@ -351,7 +357,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
351
357
|
- !ruby/object:Gem::Version
|
352
358
|
version: '0'
|
353
359
|
requirements: []
|
354
|
-
rubygems_version: 3.
|
360
|
+
rubygems_version: 3.0.3
|
355
361
|
signing_key:
|
356
362
|
specification_version: 4
|
357
363
|
summary: An API Client Generator for Ruby in Ruby!
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2019 Google LLC
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require "gapic/path_template/segment"
|
18
|
-
|
19
|
-
module Gapic
|
20
|
-
module PathTemplate
|
21
|
-
# A URI path template parser.
|
22
|
-
#
|
23
|
-
# @see https://tools.ietf.org/html/rfc6570 URI Template
|
24
|
-
#
|
25
|
-
# @!attribute [r] path_template
|
26
|
-
# @return [String] The URI path template to be parsed.
|
27
|
-
# @!attribute [r] segments
|
28
|
-
# @return [Array<Segment|String>] The segments of the parsed URI path
|
29
|
-
# template.
|
30
|
-
class Parser
|
31
|
-
# @private
|
32
|
-
# /((?<positional>\*\*?)|{(?<name>[^\/]+?)(?:=(?<template>.+?))?})/
|
33
|
-
PATH_TEMPLATE = %r{
|
34
|
-
(
|
35
|
-
(?<positional>\*\*?)
|
36
|
-
|
|
37
|
-
{(?<name>[^\/]+?)(?:=(?<template>.+?))?}
|
38
|
-
)
|
39
|
-
}x.freeze
|
40
|
-
|
41
|
-
attr_reader :path_template, :segments
|
42
|
-
|
43
|
-
# Create a new URI path template parser.
|
44
|
-
#
|
45
|
-
# @param path_template [String] The URI path template to be parsed.
|
46
|
-
def initialize path_template
|
47
|
-
@path_template = path_template
|
48
|
-
@segments = parse! path_template
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
def parse! path_template
|
54
|
-
# segments contain either Strings or segment objects
|
55
|
-
segments = []
|
56
|
-
segment_pos = 0
|
57
|
-
|
58
|
-
while (match = PATH_TEMPLATE.match path_template)
|
59
|
-
# The String before the match needs to be added to the segments
|
60
|
-
segments << match.pre_match unless match.pre_match.empty?
|
61
|
-
|
62
|
-
segment, segment_pos = segment_and_pos_from_match match, segment_pos
|
63
|
-
segments << segment
|
64
|
-
|
65
|
-
path_template = match.post_match
|
66
|
-
end
|
67
|
-
|
68
|
-
# Whatever String is unmatched needs to be added to the segments
|
69
|
-
segments << path_template unless path_template.empty?
|
70
|
-
|
71
|
-
segments
|
72
|
-
end
|
73
|
-
|
74
|
-
def segment_and_pos_from_match match, pos
|
75
|
-
if match[:positional]
|
76
|
-
[Segment.new(pos, match[:positional]), pos + 1]
|
77
|
-
else
|
78
|
-
[Segment.new(match[:name], match[:template]), pos]
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright 2019 Google LLC
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# https://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
module Gapic
|
18
|
-
module PathTemplate
|
19
|
-
# A segment in a URI path template.
|
20
|
-
#
|
21
|
-
# @see https://tools.ietf.org/html/rfc6570 URI Template
|
22
|
-
#
|
23
|
-
# @!attribute [r] name
|
24
|
-
# @return [String, Integer] The name of a named segment, or the position
|
25
|
-
# of a positional segment.
|
26
|
-
# @!attribute [r] pattern
|
27
|
-
# @return [String, nil] The pattern of the segment, nil if not set.
|
28
|
-
class Segment
|
29
|
-
attr_reader :name, :pattern
|
30
|
-
|
31
|
-
def initialize name, pattern
|
32
|
-
@name = name
|
33
|
-
@pattern = pattern
|
34
|
-
end
|
35
|
-
|
36
|
-
# Determines if the segment is positional (has a number for a name).
|
37
|
-
#
|
38
|
-
# @return [Boolean]
|
39
|
-
def positional?
|
40
|
-
name.is_a? Integer
|
41
|
-
end
|
42
|
-
|
43
|
-
# Determines if the segment is named (has a string for a name).
|
44
|
-
#
|
45
|
-
# @return [Boolean]
|
46
|
-
def named?
|
47
|
-
!positional?
|
48
|
-
end
|
49
|
-
|
50
|
-
# Determines if the segment has a pattern. Positional segments always
|
51
|
-
# have a pattern. Named segments may have a pattern if provided in the
|
52
|
-
# URI path template.
|
53
|
-
#
|
54
|
-
# @return [Boolean]
|
55
|
-
def pattern?
|
56
|
-
!@pattern.nil?
|
57
|
-
end
|
58
|
-
|
59
|
-
# @private
|
60
|
-
def == other
|
61
|
-
return false unless other.is_a? self.class
|
62
|
-
|
63
|
-
(name == other.name) && (pattern == other.pattern)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|