gapic-generator 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a5c16d4ae2bf94ccb62b00d0a7cd0d35fbebc348072649684f7550950ef370d
4
- data.tar.gz: 162528840170a3992fa85e76d17e6110779cad71d22e5c670cc07647e6c931e6
3
+ metadata.gz: c3adc22eae54587c0d4ddebad747dc1efb90ed8973c6a617a4df8f3120cee027
4
+ data.tar.gz: c7c531f3e6e0da489acc866000007bdcd7001e585f98763cf4eeeb68c677c627
5
5
  SHA512:
6
- metadata.gz: 9b0f283cae815e46051faed3bb47ce892772f3f8635b9ce85d6c1d1af7e7d66f87e5900079011abe356ff5f34e1a5e3b0a2bb5eb49d85237f47a695724b7acb1
7
- data.tar.gz: d81fb0ca1e7787beb0dd886a2cf8e58ad53b05de862b73334e1f8eafb395de6d4f30538bd53b0ff27876c6e9d14d3dc4641297b6b669d6f99c193f80a925c71d
6
+ metadata.gz: 7c9181069a5107c008cb3c276420f0f36421e0ef3fe37ac63f10fc3c00a87bb7c80444c371a084c3b8dfcf19f79b5e32939f6c8a611a1956e9837e4d421296fb
7
+ data.tar.gz: 648db155b410c7613a8f67d53b9f1319b4e784e54baf4d3f238221b4de0526438d6279af3fc14a53d2f5e5bfd8d85f5a0eeefc6542d8d92fc502870ec9a4ad8d
@@ -1,5 +1,16 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.3.0 / 2020-04-10
4
+
5
+ * Detect when a resource is referenced implicitly via child_type, and generate path helpers.
6
+ * Update grpc-google-iam-v1 dependency to require the latest version.
7
+ * Generated require graph is more sane and does not include cycles.
8
+ * The bundler entrypoint now loads the entire gem for wrapper gems.
9
+ * Generated readmes are more useful and include a quickstart.
10
+ * Package and service modules now have basic documentation.
11
+ * Overloads for methods now have basic explanatory documentation, including how to pass an empty request.
12
+ * Request object documentation no longer duplicates the method documentation.
13
+
3
14
  ### 0.2.3 / 2020-04-06
4
15
 
5
16
  * No changes
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.2.3"
19
+ VERSION = "0.3.0"
20
20
  end
21
21
  end
@@ -63,16 +63,17 @@ module Gapic
63
63
  end
64
64
 
65
65
  # Gem level files
66
- files << g("gem/gitignore.erb", ".gitignore", gem: gem)
67
- files << g("gem/version.erb", "lib/#{gem.version_file_path}", gem: gem)
68
- files << g("gem/gemspec.erb", "#{gem.name}.gemspec", gem: gem)
69
- files << g("gem/gemfile.erb", "Gemfile", gem: gem)
70
- files << g("gem/rakefile.erb", "Rakefile", gem: gem)
71
- files << g("gem/readme.erb", "README.md", gem: gem)
72
- files << g("gem/changelog.erb", "CHANGELOG.md", gem: gem)
73
- files << g("gem/rubocop.erb", ".rubocop.yml", gem: gem)
74
- files << g("gem/yardopts.erb", ".yardopts", gem: gem)
75
- files << g("gem/license.erb", "LICENSE.md", gem: gem)
66
+ files << g("gem/gitignore.erb", ".gitignore", gem: gem)
67
+ files << g("gem/version.erb", "lib/#{gem.version_file_path}", gem: gem)
68
+ files << g("gem/gemspec.erb", "#{gem.name}.gemspec", gem: gem)
69
+ files << g("gem/gemfile.erb", "Gemfile", gem: gem)
70
+ files << g("gem/rakefile.erb", "Rakefile", gem: gem)
71
+ files << g("gem/readme.erb", "README.md", gem: gem)
72
+ files << g("gem/changelog.erb", "CHANGELOG.md", gem: gem)
73
+ files << g("gem/rubocop.erb", ".rubocop.yml", gem: gem)
74
+ files << g("gem/yardopts.erb", ".yardopts", gem: gem)
75
+ files << g("gem/license.erb", "LICENSE.md", gem: gem)
76
+ files << g("gem/entrypoint.erb", "lib/#{gem.name}.rb", gem: gem)
76
77
 
77
78
  gem.proto_files.each do |proto_file|
78
79
  files << g("proto_docs/proto_file.erb", "proto_docs/#{proto_file.docs_file_path}", file: proto_file)
@@ -95,7 +95,7 @@ module Gapic
95
95
  base_type =
96
96
  if field.message?
97
97
  type = message_ruby_type field.message
98
- output ? type : "#{type} | Hash"
98
+ output ? type : "#{type}, Hash"
99
99
  elsif field.enum?
100
100
  # TODO: handle when arg message is nil and enum is the type
101
101
  message_ruby_type field.enum
@@ -37,6 +37,10 @@ module Gapic
37
37
  end
38
38
  end
39
39
 
40
+ def packages?
41
+ !packages.empty?
42
+ end
43
+
40
44
  def services
41
45
  @services ||= begin
42
46
  files = @api.generate_files
@@ -214,7 +214,7 @@ module Gapic
214
214
 
215
215
  def doc_types_for arg
216
216
  if arg.message?
217
- "#{message_ruby_type arg.message} | Hash"
217
+ "#{message_ruby_type arg.message}, Hash"
218
218
  elsif arg.enum?
219
219
  # TODO: handle when arg message is nil and enum is the type
220
220
  message_ruby_type arg.enum
@@ -45,6 +45,14 @@ module Gapic
45
45
  ruby_namespace_for_address address
46
46
  end
47
47
 
48
+ def parent_namespace
49
+ namespace.split("::")[0...-1].join("::")
50
+ end
51
+
52
+ def module_name
53
+ namespace.split("::").last
54
+ end
55
+
48
56
  def services
49
57
  @services ||= begin
50
58
  files = @api.generate_files.select { |f| f.package == @package }
@@ -78,6 +78,10 @@ module Gapic
78
78
  fix_namespace @api, "#{namespace}::#{name}"
79
79
  end
80
80
 
81
+ def module_name
82
+ proto_service_name_full.split("::").last
83
+ end
84
+
81
85
  def proto_service_file_path
82
86
  @service.parent.name.sub ".proto", "_pb.rb"
83
87
  end
@@ -114,6 +118,10 @@ module Gapic
114
118
  service_file_path.split("/").last
115
119
  end
116
120
 
121
+ def service_directory_name
122
+ service_require.split("/").last
123
+ end
124
+
117
125
  def service_require
118
126
  ruby_file_path @api, proto_service_name_full
119
127
  end
@@ -26,64 +26,42 @@ module Gapic
26
26
 
27
27
  # @private
28
28
  def lookup!
29
- resources = @api.files.flat_map { |file| lookup_file_resource_descriptors file }
30
- resources.compact.uniq
31
- end
32
-
33
- # @private
34
- def lookup_file_resource_descriptors file
35
29
  resources = []
36
- resources += file.resources.select { |resource| service_resource_types.include? resource.type }
37
- resources += file.messages.flat_map { |message| lookup_message_resources_descriptors message }
38
- resources
39
- end
40
-
41
- # @private
42
- def service_resource_types
43
- @service_resource_types ||= begin
44
- @service.methods.flat_map do |method|
45
- input_resource_types = message_resource_types method.input
46
-
47
- if @api.generate_path_helpers_output?
48
- output_resource_types = message_resource_types method.output
49
- input_resource_types + output_resource_types
50
- else
51
- input_resource_types
52
- end
53
- end.uniq
30
+ @service.methods.each do |method|
31
+ resources.concat resources_for_message(method.input)
32
+ resources.concat resources_for_message(method.output) if @api.generate_path_helpers_output?
54
33
  end
34
+ resources.uniq
55
35
  end
56
36
 
57
37
  # @private
58
- def message_resource_types message, seen_messages = []
59
- return [] if seen_messages.include? message
38
+ def resources_for_message message, seen_messages = []
39
+ resources = []
40
+ return resources if seen_messages.include? message
60
41
  seen_messages << message
61
- resource_types = []
62
- resource_types << message.resource.type if message.resource
63
- resource_types += message.nested_messages.map do |nested_message|
64
- message_resource_types nested_message, seen_messages
42
+ resources << message.resource if message.resource
43
+ message.nested_messages.each do |nested_message|
44
+ resources.concat resources_for_message(nested_message, seen_messages)
65
45
  end
66
46
  message.fields.each do |field|
67
- resource_types << field.resource_reference.type if field.resource_reference
68
- resource_types += message_resource_types field.message, seen_messages if field.message?
47
+ resources.concat resources_for_reference(field.resource_reference) if field.resource_reference
48
+ resources.concat resources_for_message(field.message, seen_messages) if field.message?
69
49
  end
70
- resource_types.flatten
50
+ resources
71
51
  end
72
52
 
73
53
  # @private
74
- def lookup_message_resources_descriptors message
75
- resources = []
76
-
77
- # We don't expect service_resource_types to iclude nil, so we can use message.resource&.type
78
- resources << message.resource if service_resource_types.include? message.resource&.type
79
-
80
- if message.nested_messages
81
- resources += message.nested_messages.flat_map do |nested_message|
82
- lookup_message_resources_descriptors nested_message
83
- end
54
+ # Given a reference (either a type or child type), return the corresponding
55
+ # resources.
56
+ def resources_for_reference reference
57
+ if (type = reference.type) && !type.empty?
58
+ Array(@api.lookup_resource_type(type))
59
+ elsif (child_type = reference.child_type) && !child_type.empty?
60
+ child_resource = @api.lookup_resource_type child_type
61
+ child_resource ? child_resource.parent_resources : []
62
+ else
63
+ []
84
64
  end
85
-
86
- resources
87
65
  end
88
66
 
89
67
  # Lookup all resources for a given service.
@@ -51,6 +51,7 @@ module Gapic
51
51
  loader.load_file fd, request.file_to_generate.include?(fd.name)
52
52
  end
53
53
  @files.each { |f| f.parent = self }
54
+ @resource_types = analyze_resources
54
55
  end
55
56
 
56
57
  def containing_api
@@ -243,8 +244,53 @@ module Gapic
243
244
  end
244
245
  end
245
246
 
247
+ # Get a resource given its type string
248
+ def lookup_resource_type resource_type
249
+ @resource_types[resource_type]
250
+ end
251
+
246
252
  private
247
253
 
254
+ # Does a pre-analysis of all resources defined in the job. This has
255
+ # two effects:
256
+ # * Side effect: each resource has its parent_resources field set.
257
+ # * A mapping from resource type to resource wrapper is returned.
258
+ def analyze_resources
259
+ # In order to set parent_resources, we first populate a mapping from
260
+ # parsed pattern to resource mapping (in the patterns variable). This
261
+ # is done in one pass along with populating the resource type mapping.
262
+ # Then, we go through all resources again, get its expected parent
263
+ # patterns, and anything that shows up in the patterns mapping is taken
264
+ # to be a parent.
265
+ types = {}
266
+ patterns = {}
267
+ @files.each do |file|
268
+ file.resources.each { |resource| populate_resource_lookups resource, types, patterns }
269
+ file.messages.each { |message| populate_message_resource_lookups message, types, patterns }
270
+ end
271
+ types.each do |_type, resource|
272
+ parents = resource.parsed_parent_patterns
273
+ .map { |pat| patterns[pat] }
274
+ .compact.uniq
275
+ resource.parent_resources.replace parents
276
+ end
277
+ types
278
+ end
279
+
280
+ def populate_resource_lookups resource, types, patterns
281
+ types[resource.type] = resource
282
+ resource.parsed_patterns.each do |pat|
283
+ patterns[pat] = resource
284
+ end
285
+ end
286
+
287
+ def populate_message_resource_lookups message, types, patterns
288
+ populate_resource_lookups message.resource, types, patterns if message.resource
289
+ message.nested_messages.each do |nested|
290
+ populate_message_resource_lookups nested, types, patterns
291
+ end
292
+ end
293
+
248
294
  def parse_parameter str
249
295
  str.scan(/\\.|,|=|[^\\,=]+/)
250
296
  .each_with_object([[String.new]]) do |tok, arr|
@@ -64,9 +64,13 @@ module Gapic
64
64
  load_service registry, s, address, docs, [6, i]
65
65
  end
66
66
 
67
+ # Load top-level resources
68
+ resource_descriptors = file_descriptor.options[:".google.api.resource_definition"] if file_descriptor.options
69
+ resources = Array(resource_descriptors).map { |descriptor| Resource.new descriptor }
70
+
67
71
  # Construct and return the file.
68
72
  File.new file_descriptor, address, docs[path], messages, enums,
69
- services, file_to_generate, registry
73
+ services, resources, file_to_generate, registry
70
74
  end
71
75
 
72
76
  # Updates the fields of a message and it's nested messages.
@@ -158,9 +162,12 @@ module Gapic
158
162
  load_field registry, e, address, docs, path + [6, i]
159
163
  end
160
164
 
165
+ resource_descriptor = descriptor.options[:".google.api.resource"] if descriptor.options
166
+ resource = resource_descriptor ? Resource.new(resource_descriptor) : nil
167
+
161
168
  # Construct, cache, and return.
162
169
  msg = Message.new(descriptor, address, docs[path], fields, extensions,
163
- nested_messages, nested_enums)
170
+ resource, nested_messages, nested_enums)
164
171
  @prior_messages << msg
165
172
  add_to_registry registry, address, msg
166
173
  end
@@ -357,16 +357,19 @@ module Gapic
357
357
  # Wrapper for a protobuf file.
358
358
  #
359
359
  # @!attribute [r] messages
360
- # @ return [Enumerable<Message>] The top level messages contained in
360
+ # @return [Enumerable<Message>] The top level messages contained in
361
361
  # this file.
362
362
  # @!attribute [r] enums
363
- # @ return [Enumerable<Enum>] The top level enums contained in this
363
+ # @return [Enumerable<Enum>] The top level enums contained in this
364
364
  # file.
365
365
  # @!attribute [r] services
366
- # @ return [Enumerable<Service>] The services contained in this file.
366
+ # @return [Enumerable<Service>] The services contained in this file.
367
+ # @!attribute [r] resources
368
+ # @return [Enumerable<Resource>] The top level resources contained in
369
+ # this file.
367
370
  class File < Proto
368
371
  extend Forwardable
369
- attr_reader :messages, :enums, :services, :registry
372
+ attr_reader :messages, :enums, :services, :resources, :registry
370
373
 
371
374
  # Initializes a message object.
372
375
  # @param descriptor [Google::Protobuf::DescriptorProto] the protobuf
@@ -379,20 +382,23 @@ module Gapic
379
382
  # file.
380
383
  # @param enums [Enumerable<Enum>] The top level enums of this file.
381
384
  # @param services [Enumerable<Service>] The services of this file.
385
+ # @param resources [Enumerable<Resource>] The resources from this file.
382
386
  # @param generate [Boolean] Whether this file should be generated.
383
387
  def initialize descriptor, address, docs, messages, enums, services,
384
- generate, registry
388
+ resources, generate, registry
385
389
  super descriptor, address, docs
386
390
  @messages = messages || []
387
391
  @enums = enums || []
388
392
  @services = services || []
393
+ @resources = resources || []
389
394
  @generate = generate
390
395
  @registry = registry
391
396
 
392
397
  # Apply parent
393
398
  @messages.each { |m| m.parent = self }
394
- @enums.each { |m| m.parent = self }
399
+ @enums.each { |m| m.parent = self }
395
400
  @services.each { |m| m.parent = self }
401
+ @resources.each { |m| m.parent = self }
396
402
  end
397
403
 
398
404
  def containing_file
@@ -413,13 +419,6 @@ module Gapic
413
419
  options[:ruby_package] if options
414
420
  end
415
421
 
416
- # @return [Array<Google::Api::ResourceDescriptor>] A representation of the resource.
417
- # This is generally intended to be attached to the "name" field.
418
- # See `google/api/resource.proto`.
419
- def resources
420
- options[:".google.api.resource_definition"] if options
421
- end
422
-
423
422
  # @!method name
424
423
  # @return [String] file name, relative to root of source tree.
425
424
  # @!method package
@@ -511,6 +510,8 @@ module Gapic
511
510
  # @ return [Enumerable<Field>] The fields of a message.
512
511
  # @!attribute [r] extensions
513
512
  # @ return [Enumerable<Field>] The extensions of a message.
513
+ # @!attribute [r] resource
514
+ # @ return [Resource,nil] A representation of the resource.
514
515
  # @!attribute [r] nested_messages
515
516
  # @ return [Enumerable<Message>] The nested message declarations of a
516
517
  # message.
@@ -518,7 +519,7 @@ module Gapic
518
519
  # @ return [Enumerable<Enum>] The nested enum declarations of a message.
519
520
  class Message < Proto
520
521
  extend Forwardable
521
- attr_reader :fields, :extensions, :nested_messages, :nested_enums
522
+ attr_reader :fields, :extensions, :resource, :nested_messages, :nested_enums
522
523
 
523
524
  # Initializes a message object.
524
525
  # @param descriptor [Google::Protobuf::DescriptorProto] the protobuf
@@ -529,15 +530,17 @@ module Gapic
529
530
  # of the proto. See #docs for more info.
530
531
  # @param fields [Enumerable<Field>] The fields of this message.
531
532
  # @param extensions [Enumerable<Field>] The extensions of this message.
533
+ # @param resource [Resource,nil] The resource of this message, or nil if none.
532
534
  # @param nested_messages [Enumerable<Message>] The nested message
533
535
  # declarations of this message.
534
536
  # @param nested_enums [Enumerable<Enum>] The nested enum declarations
535
537
  # of this message.
536
- def initialize descriptor, address, docs, fields, extensions,
538
+ def initialize descriptor, address, docs, fields, extensions, resource,
537
539
  nested_messages, nested_enums
538
540
  super descriptor, address, docs
539
541
  @fields = fields || []
540
542
  @extensions = extensions || []
543
+ @resource = resource
541
544
  @nested_messages = nested_messages || []
542
545
  @nested_enums = nested_enums || []
543
546
 
@@ -545,13 +548,7 @@ module Gapic
545
548
  @extensions.each { |x| x.parent = self }
546
549
  @nested_messages.each { |m| m.parent = self }
547
550
  @nested_enums.each { |e| e.parent = self }
548
- end
549
-
550
- # @return [Google::Api::ResourceDescriptor] A representation of the resource.
551
- # This is generally intended to be attached to the "name" field.
552
- # See `google/api/resource.proto`.
553
- def resource
554
- options[:".google.api.resource"] if options
551
+ @resource.parent = self if @resource
555
552
  end
556
553
 
557
554
  # @return [Boolean] whether this type is a map entry
@@ -736,5 +733,95 @@ module Gapic
736
733
  :options
737
734
  )
738
735
  end
736
+
737
+ # Wrapper for a protobuf Resource.
738
+ #
739
+ # Unlike most wrappers, this does not subclass the {Proto} wrapper because
740
+ # it does not use the fields exposed by that wrapper (`address`, `docs`,
741
+ # etc.) This is here principally to augment the resource definition with
742
+ # information about resource parent-child relationships.
743
+ #
744
+ # Resource parentage is defined implicitly by path patterns. The algorithm
745
+ # is as follows:
746
+ # * If the final segment of a pattern is an ID segment (i.e. `*` or some
747
+ # `{name}`) then remove it and the previous segment (which we assume to
748
+ # be the corresponding collection identifier, as described in AIP-122.)
749
+ # The resulting pattern is what we expect a parent to have.
750
+ # * If the final segment is static, then assume the pattern represents a
751
+ # singleton resource (AIP-156) and remove only that one segment. The
752
+ # resulting pattern is what we expect a parent to have.
753
+ #
754
+ # The {Resource#parsed_parent_patterns} method returns the set of patterns
755
+ # we expect of parents. It is then possible to search for resources with
756
+ # those patterns to determine what the parents are.
757
+ #
758
+ # @!attribute [rw] parent
759
+ # @return [Gapic::Schema::File,Gapic::Schema::Message] The parent object.
760
+ # @!attribute [r] descriptor
761
+ # @return [Array<Gapic::Schema::ResourceDescriptor>] The resource
762
+ # descriptor.
763
+ # @!attribute [r] parsed_patterns
764
+ # @return [Array<Array<String>>] The normalized, segmented forms of the
765
+ # patterns. Normalized means all ID segments are replaced by asterisks
766
+ # to remove non-structural differences due to different names being
767
+ # used. Segmented means simply split on slashes.
768
+ # For example, if a pattern is `"projects/{project}""`, the
769
+ # corresponding parsed pattern would be `["projects", "*"]`.
770
+ # @!attribute [r] parent_resources
771
+ # @return [Array<Gapic::Schema::Resource>] Parent resources
772
+ class Resource
773
+ extend Forwardable
774
+ attr_reader :descriptor, :parsed_patterns, :parent_resources
775
+ attr_accessor :parent
776
+
777
+ # Initializes a resource object.
778
+ # @param descriptor [Google::Protobuf::ResourceDescriptor] the protobuf
779
+ # representation of this resource.
780
+ def initialize descriptor
781
+ @parent = nil
782
+ @descriptor = descriptor
783
+ @parsed_patterns = descriptor.pattern.map do |pattern|
784
+ pattern.split("/").map do |segment|
785
+ segment =~ %r{\{[^/\}]+(=[^\}]+)?\}} ? "*" : segment
786
+ end.freeze
787
+ end.freeze
788
+ @parent_resources = []
789
+ end
790
+
791
+ # Returns the "root" of this schema.
792
+ # @return [Gapic::Schema::Api]
793
+ def containing_api
794
+ parent&.containing_api
795
+ end
796
+
797
+ # Returns the file containing this proto entity
798
+ # @return [Gapic::Schema::File]
799
+ def containing_file
800
+ parent&.containing_file
801
+ end
802
+
803
+ # Returns parsed patterns for the expected parents.
804
+ # @return [Array<Array<String>>]
805
+ def parsed_parent_patterns
806
+ @parsed_patterns.map do |pat|
807
+ parent = pat.last =~ /^\*\*?$/ ? pat[0...-2] : pat[0...-1]
808
+ parent.empty? ? nil : parent
809
+ end.compact.uniq
810
+ end
811
+
812
+ # @!method type
813
+ # @return [String] the resource type string.
814
+ # @!method pattern
815
+ # @return [Array<String>] the set of patterns.
816
+ # @!method name_field
817
+ # @return [String] the field on the resource that designates the
818
+ # resource name field. If omitted, this is assumed to be "name".
819
+ def_delegators(
820
+ :descriptor,
821
+ :type,
822
+ :pattern,
823
+ :name_field
824
+ )
825
+ end
739
826
  end
740
827
  end
@@ -0,0 +1,8 @@
1
+ <%- assert_locals gem -%>
2
+ <%= render partial: "shared/header" -%>
3
+
4
+ # This gem does not autoload during Bundler.require. To load this gem,
5
+ # issue explicit require statements for the packages desired, e.g.:
6
+ <%- gem.packages.each do |package| -%>
7
+ # require "<%= package.package_require %>"
8
+ <%- end -%>
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
25
25
 
26
26
  gem.add_dependency "gapic-common", "~> 0.2"
27
27
  <%- if gem.iam_dependency? -%>
28
- gem.add_dependency "grpc-google-iam-v1", "~> 0.6.9"
28
+ gem.add_dependency "grpc-google-iam-v1", ">= 0.6.10", "< 2.0"
29
29
  <%- end -%>
30
30
 
31
31
  gem.add_development_dependency "google-style", "~> 1.24.0"
@@ -1,4 +1,4 @@
1
- # <%= gem.title %>
1
+ # Ruby Client for the <%= gem.title %> API
2
2
 
3
3
  <%= gem.summary %>
4
4
 
@@ -12,6 +12,20 @@
12
12
  $ gem install <%= gem.name %>
13
13
  ```
14
14
 
15
+ ## Quick Start
16
+
17
+ ```ruby
18
+ require "<%= gem.entrypoint_require %>"
19
+ <%- service = gem.packages.first&.services.first -%>
20
+ <%- method = service&.methods.first -%>
21
+ <%- if service && method -%>
22
+
23
+ client = <%= service.create_client_call %>
24
+ request = my_create_request
25
+ response = client.<%= method.name %> request
26
+ <%- end -%>
27
+ ```
28
+
15
29
  ## Supported Ruby Versions
16
30
 
17
31
  This library is supported on Ruby 2.4+.
@@ -9,53 +9,23 @@ AllCops:
9
9
  - "test/**/*"
10
10
 
11
11
  Metrics/AbcSize:
12
- Exclude:
13
- <%- gem.packages.each do |package| -%>
14
- <%- package.services.each do |service| -%>
15
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
16
- <%- end -%>
17
- <%- end -%>
12
+ Enabled: false
18
13
  Metrics/ClassLength:
19
- Exclude:
20
- <%- gem.packages.each do |package| -%>
21
- <%- package.services.each do |service| -%>
22
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
23
- <%- end -%>
24
- <%- end -%>
14
+ Enabled: false
25
15
  Metrics/CyclomaticComplexity:
26
- Exclude:
27
- <%- gem.packages.each do |package| -%>
28
- <%- package.services.each do |service| -%>
29
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
30
- <%- end -%>
31
- <%- end -%>
16
+ Enabled: false
32
17
  Metrics/LineLength:
33
- Exclude:
34
- <%- gem.packages.each do |package| -%>
35
- <%- package.services.each do |service| -%>
36
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
37
- <%- end -%>
38
- <%- end -%>
18
+ Enabled: false
39
19
  Metrics/MethodLength:
40
- Exclude:
41
- <%- gem.packages.each do |package| -%>
42
- <%- package.services.each do |service| -%>
43
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
44
- <%- end -%>
45
- <%- end -%>
20
+ Enabled: false
46
21
  Metrics/PerceivedComplexity:
22
+ Enabled: false
23
+ Naming/FileName:
47
24
  Exclude:
48
- <%- gem.packages.each do |package| -%>
49
- <%- package.services.each do |service| -%>
50
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
51
- <%- end -%>
52
- <%- end -%>
25
+ - "lib/<%= gem.name %>.rb"
53
26
  Style/CaseEquality:
54
- Exclude:
55
- <%- gem.packages.each do |package| -%>
56
- <%- package.services.each do |service| -%>
57
- - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
58
- <%- end -%>
59
- <%- end -%>
27
+ Enabled: false
28
+ Style/IfUnlessModifier:
29
+ Enabled: false
60
30
  Style/ModuleFunction:
61
31
  Enabled: false
@@ -0,0 +1,17 @@
1
+ <%- assert_locals package -%>
2
+ <% @requires = capture do %>
3
+ <%- package.services.each do |service| -%>
4
+ require "<%= service.service_require %>"
5
+ <%- end -%>
6
+ require "<%= package.gem.version_require %>"
7
+ <% end %>
8
+ <%- unless package.empty? -%>
9
+ ##
10
+ # To load this package, including all its services, and instantiate a client:
11
+ #
12
+ # require "<%= package.package_require %>"
13
+ # client = <%= package.services.first.create_client_call %>
14
+ #
15
+ <%- end -%>
16
+ module <%= package.module_name %>
17
+ end
@@ -0,0 +1,32 @@
1
+ <%- assert_locals service -%>
2
+ <% @requires = capture do %>
3
+ require "gapic/common"
4
+ require "gapic/config"
5
+ require "gapic/config/method"
6
+
7
+ require "<%= service.gem.version_require %>"
8
+
9
+ require "<%= service.credentials_require %>"
10
+ <%- if service.paths? -%>
11
+ require "<%= service.paths_require %>"
12
+ <%- end -%>
13
+ <%- if service.lro? -%>
14
+ require "<%= service.operations_require %>"
15
+ <%- end -%>
16
+ require "<%= service.client_require %>"
17
+ <% end %>
18
+ ##
19
+ <%- if service.doc_description -%>
20
+ <%= indent service.doc_description, "# " %>
21
+ #
22
+ <%- end -%>
23
+ # To load this service and instantiate a client:
24
+ #
25
+ # require "<%= service.service_require %>"
26
+ # client = <%= service.create_client_call %>
27
+ #
28
+ module <%= service.module_name %>
29
+ end
30
+ <% @footer = capture do %>
31
+ <%= render partial: "service/helpers", locals: { service: service} -%>
32
+ <% end %>
@@ -1,6 +1,6 @@
1
1
  <%- assert_locals package -%>
2
- <%= render partial: "shared/header" -%>
3
-
4
- <% package.services.each do |service| %>
5
- require "<%= service.service_require %>"
6
- <% end %>
2
+ <%= render partial: "lib/package",
3
+ layout: "layouts/ruby",
4
+ locals: { package: package,
5
+ namespace: package.parent_namespace }
6
+ %>
@@ -1,8 +1,6 @@
1
1
  <%- assert_locals service -%>
2
- <%= render partial: "shared/header" -%>
3
-
4
- require "<%= service.client_require %>"
5
- <%- if service.lro? -%>
6
- require "<%= service.operations_require %>"
7
- <%- end -%>
8
- require "<%= service.credentials_require %>"
2
+ <%= render partial: "lib/service",
3
+ layout: "layouts/ruby",
4
+ locals: { service: service,
5
+ namespace: service.namespace }
6
+ %>
@@ -0,0 +1,3 @@
1
+ <%- assert_locals service -%>
2
+ helper_path = ::File.join __dir__, "<%= service.service_directory_name%>", "helpers.rb"
3
+ require "<%= service.helpers_require %>" if ::File.file? helper_path
@@ -1,19 +1,7 @@
1
1
  <%- assert_locals service -%>
2
2
  <% @requires = capture do %>
3
- require "gapic/common"
4
- require "gapic/config"
5
- require "gapic/config/method"
6
-
7
3
  <%= render partial: "service/client/requires", locals: { service: service} -%>
8
- require "<%= service.gem.version_require %>"
9
4
  require "<%= service.proto_service_require %>"
10
- require "<%= service.credentials_require %>"
11
- <%- if service.paths? -%>
12
- require "<%= service.paths_require %>"
13
- <%- end -%>
14
- <%- if service.lro? -%>
15
- require "<%= service.operations_require %>"
16
- <%- end -%>
17
5
  <% end %>
18
6
  ##
19
7
  # Client for the <%= service.name %> service.
@@ -137,7 +125,3 @@ class <%= service.client_name %>
137
125
 
138
126
  <%= indent_tail render(partial: "service/client/config", locals: { service: service }), 2 %>
139
127
  end
140
-
141
- <% @footer = capture do %>
142
- <%= render partial: "service/client/helpers", locals: { service: service} %>
143
- <% end %>
@@ -1,10 +1,6 @@
1
1
  <%- assert_locals service -%>
2
2
  <% @requires = capture do %>
3
- require "gapic/common"
4
3
  require "gapic/operation"
5
-
6
- require "<%= service.gem.version_require %>"
7
- require "<%= service.client_require %>"
8
4
  require "<%= service.lro_service.proto_service_require %>"
9
5
  <% end %>
10
6
  # Service that implements Longrunning Operations API.
@@ -1,15 +1,21 @@
1
1
  <%- assert_locals method -%>
2
2
  # @overload <%= method.name %>(request, options = nil)
3
- # @param request [<%= method.request_type %> | Hash]
4
- <%- if method.doc_description -%>
5
- <%= indent method.doc_description, "# " %>
6
- <%- end -%>
3
+ # Pass arguments to `<%= method.name %>` via a request object, either of type
4
+ # {<%= method.request_type %>} or an equivalent Hash.
5
+ #
6
+ # @param request [<%= method.request_type %>, Hash]
7
+ # A request object representing the call parameters. Required. To specify no
8
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
7
9
  # @param options [Gapic::CallOptions, Hash]
8
10
  # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
9
11
  <%-if method.arguments.any?-%>
10
12
  #
11
13
  <%- arg_list = method.arguments.map { |arg| "#{arg.name}: nil"}.join ", " -%>
12
14
  # @overload <%= method.name %>(<%= arg_list %>)
15
+ # Pass arguments to `<%= method.name %>` via keyword arguments. Note that at
16
+ # least one keyword argument is required. To specify no parameters, or to keep all
17
+ # the default parameter values, pass an empty Hash as a request object (see above).
18
+ #
13
19
  <%- method.arguments.each do |arg| -%>
14
20
  # @param <%= arg.name %> [<%= arg.doc_types %>]
15
21
  <%- if arg.doc_description -%>
@@ -17,4 +23,3 @@
17
23
  <%- end -%>
18
24
  <%- end -%>
19
25
  <%- end -%>
20
- #
@@ -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
4
  # @param options [Gapic::CallOptions, Hash]
5
5
  # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
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.2.3
4
+ version: 0.3.0
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-04-06 00:00:00.000000000 Z
13
+ date: 2020-04-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -251,6 +251,7 @@ files:
251
251
  - lib/google/rpc/status.pb.rb
252
252
  - templates/default/gem/_version.erb
253
253
  - templates/default/gem/changelog.erb
254
+ - templates/default/gem/entrypoint.erb
254
255
  - templates/default/gem/gemfile.erb
255
256
  - templates/default/gem/gemspec.erb
256
257
  - templates/default/gem/gitignore.erb
@@ -264,6 +265,8 @@ files:
264
265
  - templates/default/helpers/filepath_helper.rb
265
266
  - templates/default/helpers/namespace_helper.rb
266
267
  - templates/default/layouts/_ruby.erb
268
+ - templates/default/lib/_package.erb
269
+ - templates/default/lib/_service.erb
267
270
  - templates/default/package.erb
268
271
  - templates/default/proto_docs/_enum.erb
269
272
  - templates/default/proto_docs/_message.erb
@@ -271,11 +274,11 @@ files:
271
274
  - templates/default/proto_docs/proto_file.erb
272
275
  - templates/default/proto_docs/readme.erb
273
276
  - templates/default/service.erb
277
+ - templates/default/service/_helpers.erb
274
278
  - templates/default/service/client.erb
275
279
  - templates/default/service/client/_client.erb
276
280
  - templates/default/service/client/_config.erb
277
281
  - templates/default/service/client/_credentials.erb
278
- - templates/default/service/client/_helpers.erb
279
282
  - templates/default/service/client/_operations.erb
280
283
  - templates/default/service/client/_paths.erb
281
284
  - templates/default/service/client/_requires.erb
@@ -1,9 +0,0 @@
1
- # rubocop:disable Lint/HandleExceptions
2
-
3
- # Once client is loaded, load helpers.rb if it exists.
4
- begin
5
- require "<%= service.helpers_require %>"
6
- rescue LoadError
7
- end
8
-
9
- # rubocop:enable Lint/HandleExceptions