gapic-generator 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87900df01c425c43c7c7ac1a46965b2324af78eb6c56b91e6cfe36eb0abf3d56
4
- data.tar.gz: 3f72d4b99665d5e235332854e4bbd4cc69f181e08e66fff9a2444cdbd9f44693
3
+ metadata.gz: 7758f2d15a52b89f57555f192cf9d477cbfdbd9788578ba30b5e04d9c468ed85
4
+ data.tar.gz: ef2c5bd9924646eea488db7060dc654dc0cc2ff2ad1d5736e4f04cad217e0fe4
5
5
  SHA512:
6
- metadata.gz: 89550d2af9728e7efdb9a3813fa50bf237dc8322057fce25653fba88aae3871672e50af88d0844e4c2ff34d725734236500e5c17cf0db889e0d517a67852760e
7
- data.tar.gz: 653271d51b4f3142d99b21cee2dff0146ddea8768a3d2d128cad0fc3914a498cac532223b53773145a33c57d5167059d1d2c8fd29b17b66d51bf7cb7c1d792d8
6
+ metadata.gz: 6d28f3903643f3b86770f83538dcaa669668bcd9f89e85592bbc6680c95c13fc043b323cf406fa0fa37b0ad0ad21ed30bb56ed42c7a2be0b423cbfc4c0b7c423
7
+ data.tar.gz: a98b3d1af7be74a680e0b738b4d0753130f90c51ef71fb181a94189d1806b947338558826cd3e4f5b8c3315897546d2e36a1ce5d99d58dd501fd5aa5e8c3a76d
@@ -1,5 +1,17 @@
1
1
  # Release History for gapic-generator
2
2
 
3
+ ### 0.1.7 / 2020-03-18
4
+
5
+ * Path modules extend self so helpers can be invoked on them directly
6
+ * Trigger IAM dependency for IAM V1 files other than iam_policy.proto
7
+
8
+ ### 0.1.6 / 2020-03-17
9
+
10
+ * Generated libraries now depend on gapic-common 0.2
11
+ * Convert cross-reference syntax in proto docs to YARD cross-reference links.
12
+ * Preserve call options in LROs
13
+ * Fix implicit kwarg warnings under Ruby 2.7
14
+
3
15
  ### 0.1.5 / 2020-03-13
4
16
 
5
17
  * More improvements to escaping of curly braces.
@@ -22,25 +22,21 @@ module Gapic
22
22
  #
23
23
  module FormattingUtils
24
24
  @brace_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*[^`\\])?\{(?<inside>[^\s][^}]*)\}(?<post>.*)\z/m
25
+ @xref_detector = /\A(?<pre>[^`]*(`[^`]*`[^`]*)*)?\[(?<text>[\w\.]+)\]\[(?<addr>[\w\.]+)\](?<post>.*)\z/m
25
26
  @list_element_detector = /\A\s*(\*|\+|-|[0-9a-zA-Z]+\.)\s/
26
27
 
27
28
  class << self
28
29
  ##
29
- # Given an enumerable of lines, escape braces that look like yardoc type
30
- # links. Tries to be smart about handling only braces that would be
31
- # interpreted by yard (i.e. those that are not part of preformatted text
32
- # blocks).
30
+ # Given an enumerable of lines, performs yardoc formatting, including:
31
+ # * Interpreting cross-references identified as described in AIP 192
32
+ # * Escaping literal braces that look like yardoc type links
33
+ #
34
+ # Tries to be smart about exempting preformatted text blocks.
33
35
  #
34
36
  # @param lines [Enumerable<String>]
35
37
  # @return [Enumerable<String>]
36
38
  #
37
- def escape_braces lines
38
- # This looks for braces that:
39
- # * Are opened and closed on the same line
40
- # * Are not nested
41
- # * Are not located between backticks
42
- # * Are not in a preformatted block
43
- #
39
+ def format_doc_lines api, lines
44
40
  # To detect preformatted blocks, this tracks the "expected" base indent
45
41
  # according to Markdown. Specifically, this is the effective indent of
46
42
  # previous block, which is normally 0 except if we're in a list item.
@@ -55,7 +51,10 @@ module Gapic
55
51
  in_block = nil
56
52
  else
57
53
  in_block, base_indent = update_indent_state in_block, base_indent, line, indent
58
- line = escape_line_braces line if in_block == false
54
+ if in_block == false
55
+ line = escape_line_braces line
56
+ line = format_line_xrefs api, line
57
+ end
59
58
  end
60
59
  line
61
60
  end
@@ -104,6 +103,53 @@ module Gapic
104
103
  end
105
104
  line
106
105
  end
106
+
107
+ def format_line_xrefs api, line
108
+ while (m = @xref_detector.match line)
109
+ entity = api.lookup m[:addr]
110
+ return line if entity.nil?
111
+ yard_link = yard_link_for_entity entity, m[:text]
112
+ return line if yard_link.nil?
113
+ line = "#{m[:pre]}#{yard_link}#{m[:post]}"
114
+ end
115
+ line
116
+ end
117
+
118
+ ##
119
+ # Generate a YARD-style cross-reference for the given entity.
120
+ #
121
+ # @param entity [Gapic::Schema::Proto] the entity to link to
122
+ # @param text [String] the text for the link
123
+ # @return [String] YARD cross-reference syntax
124
+ #
125
+ def yard_link_for_entity entity, text
126
+ # As a special case, omit the service "google.longrunning.Operations"
127
+ # and its methods. This is because the generator creates
128
+ # service-specific copies of the operations client, rather than a
129
+ # Google::Longrunning::Operations::Client class, and there is in
130
+ # general no way to tell what the actual service-specific namespace is.
131
+ return text if entity.address[0, 3] == ["google", "longrunning", "Operations"]
132
+
133
+ case entity
134
+ when Gapic::Schema::Service
135
+ "{#{convert_address_to_ruby entity}::Client #{text}}"
136
+ when Gapic::Schema::Method
137
+ "{#{convert_address_to_ruby entity.parent}::Client##{entity.name.underscore} #{text}}"
138
+ when Gapic::Schema::Message, Gapic::Schema::Enum, Gapic::Schema::EnumValue
139
+ "{#{convert_address_to_ruby entity} #{text}}"
140
+ when Gapic::Schema::Field
141
+ "{#{convert_address_to_ruby entity.parent}##{entity.name} #{text}}"
142
+ end
143
+ end
144
+
145
+ def convert_address_to_ruby entity
146
+ file = entity.containing_file
147
+ api = file.containing_api
148
+ address = entity.address
149
+ address = address.join "." if address.is_a? Array
150
+ address = address.sub file.package, file.ruby_package if file.ruby_package&.present?
151
+ address.split(".").reject(&:empty?).map(&:camelize).map { |node| api.fix_namespace node }.join("::")
152
+ end
107
153
  end
108
154
  end
109
155
  end
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Gapic
18
18
  module Generator
19
- VERSION = "0.1.5"
19
+ VERSION = "0.1.7"
20
20
  end
21
21
  end
@@ -53,6 +53,14 @@ module Gapic
53
53
  @files.each { |f| f.parent = self }
54
54
  end
55
55
 
56
+ def containing_api
57
+ self
58
+ end
59
+
60
+ def containing_file
61
+ nil
62
+ end
63
+
56
64
  def lookup address
57
65
  address = address.join "." if address.is_a? Array
58
66
  @files.each do |f|
@@ -95,6 +95,18 @@ module Gapic
95
95
  @docs = docs
96
96
  end
97
97
 
98
+ # Returns the "root" of this schema.
99
+ # @return [Gapic::Schema::Api]
100
+ def containing_api
101
+ parent&.containing_api
102
+ end
103
+
104
+ # Returns the file containing this proto entity
105
+ # @return [Gapic::Schema::File]
106
+ def containing_file
107
+ parent&.containing_file
108
+ end
109
+
98
110
  # Gets the cleaned up leading comments documentation
99
111
  def docs_leading_comments
100
112
  return nil if @docs.nil?
@@ -102,7 +114,7 @@ module Gapic
102
114
 
103
115
  lines = @docs.leading_comments.each_line.to_a
104
116
  lines.map! { |line| line.start_with?(" ") ? line[1..-1] : line }
105
- lines = FormattingUtils.escape_braces lines
117
+ lines = FormattingUtils.format_doc_lines containing_api, lines
106
118
  lines.join
107
119
  end
108
120
 
@@ -376,6 +388,10 @@ module Gapic
376
388
  @services.each { |m| m.parent = self }
377
389
  end
378
390
 
391
+ def containing_file
392
+ self
393
+ end
394
+
379
395
  def lookup address
380
396
  address = address.split(".").reject(&:empty?).join(".")
381
397
  @registry[address]
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
 
24
24
  gem.required_ruby_version = ">= 2.4"
25
25
 
26
- gem.add_dependency "gapic-common", "~> 0.1.0"
26
+ gem.add_dependency "gapic-common", "~> 0.2"
27
27
  <%- if gem.iam_dependency? -%>
28
28
  gem.add_dependency "grpc-google-iam-v1", "~> 0.6.9"
29
29
  <%- end -%>
@@ -57,3 +57,5 @@ Style/CaseEquality:
57
57
  - "lib/<%= service.client_file_path.sub "client.rb", "*.rb" %>"
58
58
  <%- end -%>
59
59
  <%- end -%>
60
+ Style/ModuleFunction:
61
+ Enabled: false
@@ -114,7 +114,7 @@ class GemPresenter
114
114
  end
115
115
 
116
116
  def iam_dependency?
117
- @api.files.map(&:name).include? "google/iam/v1/iam_policy.proto"
117
+ @api.files.map(&:name).any? { |f| f.start_with? "google/iam/v1/" }
118
118
  end
119
119
 
120
120
  private
@@ -5,4 +5,5 @@ module Paths
5
5
  <%= indent render(partial: "service/client/resource", locals: { resource: resource }), 2 %>
6
6
 
7
7
  <%- end %>
8
+ extend self
8
9
  end
@@ -1,6 +1,6 @@
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
@@ -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 %>
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
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.1.5
4
+ version: 0.1.7
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-03-14 00:00:00.000000000 Z
13
+ date: 2020-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack