gapic-generator 0.3.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -0
- data/lib/gapic/formatting_utils.rb +7 -7
- 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/segment.rb +7 -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 +28 -2
- data/lib/gapic/presenters/method_presenter.rb +23 -17
- data/lib/gapic/presenters/package_presenter.rb +11 -3
- data/lib/gapic/presenters/resource_presenter.rb +55 -35
- data/lib/gapic/presenters/service_presenter.rb +66 -23
- data/lib/gapic/ruby_info.rb +93 -0
- data/lib/gapic/schema/api.rb +63 -1
- 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.erb +1 -1
- data/templates/default/service/client/_client.erb +17 -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/_multi.erb +4 -7
- data/templates/default/service/client/resource/_single.erb +2 -3
- data/templates/default/service/credentials.erb +1 -1
- data/templates/default/service/operations.erb +1 -1
- data/templates/default/service/paths.erb +1 -1
- data/templates/default/service/test/_resource.erb +16 -0
- data/templates/default/service/test/client.erb +17 -4
- data/templates/default/service/test/client_operations.erb +3 -4
- data/templates/default/service/test/client_paths.erb +17 -0
- data/templates/default/service/test/method/_configure.erb +19 -0
- metadata +8 -3
@@ -5,12 +5,13 @@
|
|
5
5
|
<%= @requires -%>
|
6
6
|
<%- end -%>
|
7
7
|
|
8
|
-
<%- namespace.split("::").
|
8
|
+
<%- namespace_components = namespace.split("::").reject(&:empty?) -%>
|
9
|
+
<%- namespace_components.each_with_index do |ns, i| -%>
|
9
10
|
<%= indent "module #{ns}", i*2 %>
|
10
11
|
<%- end -%>
|
11
|
-
<%= indent yield,
|
12
|
-
<%-
|
13
|
-
<%= indent "end", (
|
12
|
+
<%= indent yield, namespace_components.count*2 %>
|
13
|
+
<%- namespace_components.count.times do |i| -%>
|
14
|
+
<%= indent "end", (namespace_components.count-1-i)*2 %>
|
14
15
|
<%- end -%>
|
15
16
|
<%- if instance_variable_defined? :@footer -%>
|
16
17
|
|
@@ -6,7 +6,9 @@ require "gapic/config/method"
|
|
6
6
|
|
7
7
|
require "<%= service.gem.version_require %>"
|
8
8
|
|
9
|
+
<%- unless service.generic_endpoint? -%>
|
9
10
|
require "<%= service.credentials_require %>"
|
11
|
+
<%- end -%>
|
10
12
|
<%- if service.paths? -%>
|
11
13
|
require "<%= service.paths_require %>"
|
12
14
|
<%- end -%>
|
@@ -10,8 +10,8 @@
|
|
10
10
|
<%- end -%>
|
11
11
|
<%- end -%>
|
12
12
|
class <%= message.name %>
|
13
|
-
include Google::Protobuf::MessageExts
|
14
|
-
extend Google::Protobuf::MessageExts::ClassMethods
|
13
|
+
include ::Google::Protobuf::MessageExts
|
14
|
+
extend ::Google::Protobuf::MessageExts::ClassMethods
|
15
15
|
<%- message.nested_messages.each do |submsg| -%>
|
16
16
|
|
17
17
|
<%= indent_tail render(partial: "proto_docs/message", locals: { message: submsg }), 2 %>
|
@@ -29,7 +29,7 @@ class <%= service.client_name %>
|
|
29
29
|
# To modify the configuration for all <%= service.name %> clients:
|
30
30
|
#
|
31
31
|
# <%= service.client_name_full %>.configure do |config|
|
32
|
-
# config.timeout =
|
32
|
+
# config.timeout = 10.0
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
# @yield [config] Configure the <%= service.client_name %> client.
|
@@ -75,7 +75,7 @@ class <%= service.client_name %>
|
|
75
75
|
# configuration:
|
76
76
|
#
|
77
77
|
# client = <%= service.client_name_full %>.new do |config|
|
78
|
-
# config.timeout =
|
78
|
+
# config.timeout = 10.0
|
79
79
|
# end
|
80
80
|
#
|
81
81
|
# @yield [config] Configure the <%= service.name %> client.
|
@@ -96,19 +96,23 @@ class <%= service.client_name %>
|
|
96
96
|
|
97
97
|
# Create credentials
|
98
98
|
credentials = @config.credentials
|
99
|
+
<%- unless service.generic_endpoint? -%>
|
99
100
|
credentials ||= Credentials.default scope: @config.scope
|
100
101
|
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
101
102
|
credentials = Credentials.new credentials, scope: @config.scope
|
102
103
|
end
|
103
|
-
|
104
|
+
<%- end -%>
|
105
|
+
@quota_project_id = @config.quota_project
|
106
|
+
@quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
|
104
107
|
|
105
108
|
<%- if service.lro? -%>
|
106
109
|
<%= service.lro_client_ivar %> = <%= service.operations_name %>.new do |config|
|
107
110
|
config.credentials = credentials
|
111
|
+
config.endpoint = @config.endpoint
|
108
112
|
end
|
109
113
|
|
110
114
|
<%- end -%>
|
111
|
-
@<%= service.stub_name %> = Gapic::ServiceStub.new(
|
115
|
+
@<%= service.stub_name %> = ::Gapic::ServiceStub.new(
|
112
116
|
<%= service.proto_service_stub_name_full %>,
|
113
117
|
credentials: credentials,
|
114
118
|
endpoint: @config.endpoint,
|
@@ -117,6 +121,15 @@ class <%= service.client_name %>
|
|
117
121
|
)
|
118
122
|
end
|
119
123
|
|
124
|
+
<%- if service.lro? -%>
|
125
|
+
##
|
126
|
+
# Get the associated client for long-running operations.
|
127
|
+
#
|
128
|
+
# @return [<%= service.operations_name_full %>]
|
129
|
+
#
|
130
|
+
attr_reader :<%= service.lro_client_var %>
|
131
|
+
|
132
|
+
<%- end -%>
|
120
133
|
# Service calls
|
121
134
|
<%- service.methods.each do |method| -%>
|
122
135
|
|
@@ -20,22 +20,22 @@
|
|
20
20
|
# to 20 seconds, and all remaining timeouts to 10 seconds:
|
21
21
|
#
|
22
22
|
# <%= service.client_name_full %>.configure do |config|
|
23
|
-
# config.timeout =
|
24
|
-
# config.rpcs.<%= method_service.methods.first.name %>.timeout =
|
23
|
+
# config.timeout = 10.0
|
24
|
+
# config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
# To apply the above configuration only to a new client:
|
28
28
|
#
|
29
29
|
# client = <%= service.client_name_full %>.new do |config|
|
30
|
-
# config.timeout =
|
31
|
-
# config.rpcs.<%= method_service.methods.first.name %>.timeout =
|
30
|
+
# config.timeout = 10.0
|
31
|
+
# config.rpcs.<%= method_service.methods.first.name %>.timeout = 20.0
|
32
32
|
# end
|
33
33
|
#
|
34
34
|
<%- end -%>
|
35
35
|
# @!attribute [rw] endpoint
|
36
36
|
# The hostname or hostname:port of the service endpoint.
|
37
37
|
# Defaults to `<%= service.client_endpoint.inspect %>`.
|
38
|
-
# @return [String]
|
38
|
+
# @return [::String]
|
39
39
|
# @!attribute [rw] credentials
|
40
40
|
# Credentials to send with calls. You may provide any of the following types:
|
41
41
|
# * (`String`) The path to a service account key file in JSON format
|
@@ -47,29 +47,29 @@
|
|
47
47
|
# * (`GRPC::Core::Channel`) a gRPC channel with included credentials
|
48
48
|
# * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
|
49
49
|
# * (`nil`) indicating no credentials
|
50
|
-
# @return [Object]
|
50
|
+
# @return [::Object]
|
51
51
|
# @!attribute [rw] scope
|
52
52
|
# The OAuth scopes
|
53
|
-
# @return [Array
|
53
|
+
# @return [::Array<::String>]
|
54
54
|
# @!attribute [rw] lib_name
|
55
55
|
# The library name as recorded in instrumentation and logging
|
56
|
-
# @return [String]
|
56
|
+
# @return [::String]
|
57
57
|
# @!attribute [rw] lib_version
|
58
58
|
# The library version as recorded in instrumentation and logging
|
59
|
-
# @return [String]
|
59
|
+
# @return [::String]
|
60
60
|
# @!attribute [rw] channel_args
|
61
61
|
# Extra parameters passed to the gRPC channel. Note: this is ignored if a
|
62
62
|
# `GRPC::Core::Channel` object is provided as the credential.
|
63
|
-
# @return [Hash]
|
63
|
+
# @return [::Hash]
|
64
64
|
# @!attribute [rw] interceptors
|
65
65
|
# An array of interceptors that are run before calls are executed.
|
66
|
-
# @return [Array
|
66
|
+
# @return [::Array<::GRPC::ClientInterceptor>]
|
67
67
|
# @!attribute [rw] timeout
|
68
|
-
# The call timeout in
|
69
|
-
# @return [Numeric]
|
68
|
+
# The call timeout in seconds.
|
69
|
+
# @return [::Numeric]
|
70
70
|
# @!attribute [rw] metadata
|
71
71
|
# Additional gRPC headers to be sent with the call.
|
72
|
-
# @return [Hash{Symbol
|
72
|
+
# @return [::Hash{::Symbol=>::String}]
|
73
73
|
# @!attribute [rw] retry_policy
|
74
74
|
# The retry policy. The value is a hash with the following keys:
|
75
75
|
# * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
|
@@ -77,25 +77,29 @@
|
|
77
77
|
# * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
|
78
78
|
# * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
|
79
79
|
# trigger a retry.
|
80
|
-
# @return [Hash]
|
80
|
+
# @return [::Hash]
|
81
|
+
# @!attribute [rw] quota_project
|
82
|
+
# A separate project against which to charge quota.
|
83
|
+
# @return [::String]
|
81
84
|
#
|
82
85
|
class Configuration
|
83
|
-
extend Gapic::Config
|
86
|
+
extend ::Gapic::Config
|
84
87
|
|
85
|
-
config_attr :endpoint,
|
86
|
-
config_attr :credentials,
|
88
|
+
config_attr :endpoint, <%= service.client_endpoint.inspect %>, ::String
|
89
|
+
config_attr :credentials, nil do |value|
|
87
90
|
allowed = [::String, ::Hash, ::Proc, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
|
88
91
|
allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
|
89
92
|
allowed.any? { |klass| klass === value }
|
90
93
|
end
|
91
|
-
config_attr :scope,
|
92
|
-
config_attr :lib_name,
|
93
|
-
config_attr :lib_version,
|
94
|
-
config_attr(:channel_args,
|
95
|
-
config_attr :interceptors,
|
96
|
-
config_attr :timeout,
|
97
|
-
config_attr :metadata,
|
98
|
-
config_attr :retry_policy,
|
94
|
+
config_attr :scope, nil, ::String, ::Array, nil
|
95
|
+
config_attr :lib_name, nil, ::String, nil
|
96
|
+
config_attr :lib_version, nil, ::String, nil
|
97
|
+
config_attr(:channel_args, <%= service.config_channel_args.inspect %>, ::Hash, nil)
|
98
|
+
config_attr :interceptors, nil, ::Array, nil
|
99
|
+
config_attr :timeout, nil, ::Numeric, nil
|
100
|
+
config_attr :metadata, nil, ::Hash, nil
|
101
|
+
config_attr :retry_policy, nil, ::Hash, ::Proc, nil
|
102
|
+
config_attr :quota_project, nil, ::String, nil
|
99
103
|
|
100
104
|
# @private
|
101
105
|
def initialize parent_config = nil
|
@@ -111,7 +115,7 @@ class Configuration
|
|
111
115
|
def rpcs
|
112
116
|
@rpcs ||= begin
|
113
117
|
parent_rpcs = nil
|
114
|
-
parent_rpcs = @parent_config.rpcs if @parent_config&.respond_to?
|
118
|
+
parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config&.respond_to?(:rpcs)
|
115
119
|
Rpcs.new parent_rpcs
|
116
120
|
end
|
117
121
|
end
|
@@ -137,7 +141,7 @@ class Configuration
|
|
137
141
|
<%- method_service.methods.each do |method| -%>
|
138
142
|
##
|
139
143
|
# RPC-specific configuration for `<%= method.name %>`
|
140
|
-
# @return [Gapic::Config::Method]
|
144
|
+
# @return [::Gapic::Config::Method]
|
141
145
|
#
|
142
146
|
attr_reader :<%= method.name %>
|
143
147
|
<%- end -%>
|
@@ -146,7 +150,7 @@ class Configuration
|
|
146
150
|
def initialize parent_rpcs = nil
|
147
151
|
<%- method_service.methods.each do |method| -%>
|
148
152
|
<%= method.name %>_config = parent_rpcs&.<%= method.name %> if parent_rpcs&.respond_to? :<%= method.name %>
|
149
|
-
@<%= method.name %> = Gapic::Config::Method.new <%= method.name %>_config
|
153
|
+
@<%= method.name %> = ::Gapic::Config::Method.new <%= method.name %>_config
|
150
154
|
<%- end -%>
|
151
155
|
|
152
156
|
yield self if block_given?
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require "googleauth"
|
4
4
|
<% end %>
|
5
5
|
# Credentials for the <%= service.name %> API.
|
6
|
-
class <%= service.credentials_name %> < Google::Auth::Credentials
|
6
|
+
class <%= service.credentials_name %> < ::Google::Auth::Credentials
|
7
7
|
<%- if service.client_scopes.any? -%>
|
8
8
|
self.scope = [
|
9
9
|
<%- service.client_scopes.each_with_index do |client_scope, index| -%>
|
@@ -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
|