gapic-generator 0.1.3 → 0.1.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac1010a66ffc02b0775927f2d4407dbb28ad35ac6be10dafe5f59953b79afd34
|
4
|
+
data.tar.gz: f30721b9e721bd6ae5ba2d17cbc0158dcd5983ea53d7b53128b029dc37245886
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d44bfe9a92b92b4417fdb59c8cf3fcc727d43fb83a66502e10c6689bf95d5934038d7c7928a6df4152a1e2f410699dc06708cd841f9538fa29a3a609388c9c9e
|
7
|
+
data.tar.gz: 5c21836f4a939dd7d9b5bf6ac6ace693aa122c9d81eb3df3c44a1d55df29c9d2a74cc4b5823ba9f71809549ec108b97bbdc61f0c6675480233abd208498c31c0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Release History for gapic-generator
|
2
2
|
|
3
|
+
### 0.1.4 / 2020-03-12
|
4
|
+
|
5
|
+
* Fixed over-escaping of curly braces in preformatted blocks in the yardocs.
|
6
|
+
* Fixed typo in authentication document.
|
7
|
+
|
3
8
|
### 0.1.3 / 2020-03-11
|
4
9
|
|
5
10
|
* Generated numeric constants are formatted with underscores if necessary.
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020 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 "bigdecimal"
|
18
|
+
|
19
|
+
module Gapic
|
20
|
+
##
|
21
|
+
# Various string formatting utils
|
22
|
+
#
|
23
|
+
module FormattingUtils
|
24
|
+
@brace_detector = /\A([^`]*(`[^`]*`[^`]*)*[^`\\])?\{([\w,]+)\}(.*)\z/m
|
25
|
+
@list_element_detector = /\A\s*(\*|\+|-|[0-9a-zA-Z]+\.)\s/
|
26
|
+
|
27
|
+
class << self
|
28
|
+
##
|
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).
|
33
|
+
#
|
34
|
+
# @param lines [Enumerable<String>]
|
35
|
+
# @return [Enumerable<String>]
|
36
|
+
#
|
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
|
+
#
|
44
|
+
# To detect preformatted blocks, this tracks the "expected" base indent
|
45
|
+
# according to Markdown. Specifically, this is the effective indent of
|
46
|
+
# previous block, which is normally 0 except if we're in a list item.
|
47
|
+
# Then, if a block is indented at least 4 spaces past that expected
|
48
|
+
# indent (and as long as it remains so), those lines are considered
|
49
|
+
# preformatted.
|
50
|
+
in_block = nil
|
51
|
+
base_indent = 0
|
52
|
+
lines.map do |line|
|
53
|
+
indent = line_indent line
|
54
|
+
if indent.nil?
|
55
|
+
in_block = nil
|
56
|
+
else
|
57
|
+
in_block, base_indent = update_indent_state in_block, base_indent, line, indent
|
58
|
+
line = escape_line_braces line if in_block == false
|
59
|
+
end
|
60
|
+
line
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Given a number, format it in such a way that Rubocop will be happy.
|
66
|
+
# Specifically, we add underscores if the magnitude is at least 10_000.
|
67
|
+
# This works for both integers and floats.
|
68
|
+
#
|
69
|
+
# @param value [Numeric]
|
70
|
+
# @return [String]
|
71
|
+
#
|
72
|
+
def format_number value
|
73
|
+
return value.to_s if value.abs < 10_000
|
74
|
+
str = value.is_a?(Integer) ? value.to_s : BigDecimal(value.to_f.to_s).to_s("F")
|
75
|
+
re = /^(-?\d+)(\d\d\d)([_\.][_\.\d]+)?$/
|
76
|
+
while (m = re.match str)
|
77
|
+
str = "#{m[1]}_#{m[2]}#{m[3]}"
|
78
|
+
end
|
79
|
+
str
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def update_indent_state in_block, base_indent, line, indent
|
85
|
+
if in_block != true && @list_element_detector =~ line
|
86
|
+
in_block = false
|
87
|
+
indent = base_indent if indent > base_indent
|
88
|
+
base_indent = (indent + 7) / 4 * 4
|
89
|
+
else
|
90
|
+
in_block = indent >= base_indent + 4 unless in_block == false
|
91
|
+
base_indent = indent / 4 * 4 if in_block == false && indent < base_indent
|
92
|
+
end
|
93
|
+
[in_block, base_indent]
|
94
|
+
end
|
95
|
+
|
96
|
+
def line_indent line
|
97
|
+
m = /^( *)\S/.match line
|
98
|
+
m.nil? ? nil : m[1].length
|
99
|
+
end
|
100
|
+
|
101
|
+
def escape_line_braces line
|
102
|
+
while (m = @brace_detector.match line)
|
103
|
+
line = "#{m[1]}\\\\{#{m[3]}}#{m[4]}"
|
104
|
+
end
|
105
|
+
line
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -14,6 +14,8 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
+
require "gapic/formatting_utils"
|
18
|
+
|
17
19
|
module Gapic
|
18
20
|
module Schema
|
19
21
|
# Base class for all generic proto types including: enums, messages,
|
@@ -98,13 +100,10 @@ module Gapic
|
|
98
100
|
return nil if @docs.nil?
|
99
101
|
return nil if @docs.leading_comments.empty?
|
100
102
|
|
101
|
-
@docs
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
.join
|
106
|
-
.split("{").join("\\\\\\{") # The only safe way to replace with \ characters...
|
107
|
-
.split("}").join("\\}")
|
103
|
+
lines = @docs.leading_comments.each_line.to_a
|
104
|
+
lines.map! { |line| line.start_with?(" ") ? line[1..-1] : line }
|
105
|
+
lines = FormattingUtils.escape_braces lines
|
106
|
+
lines.join
|
108
107
|
end
|
109
108
|
|
110
109
|
# @!method path
|
@@ -14,8 +14,8 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
require "bigdecimal"
|
18
17
|
require "active_support/inflector"
|
18
|
+
require "gapic/formatting_utils"
|
19
19
|
|
20
20
|
module DefaultHelper
|
21
21
|
def prepend_with input, prepend
|
@@ -41,13 +41,7 @@ module DefaultHelper
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def format_number value
|
44
|
-
|
45
|
-
str = value.is_a?(Integer) ? value.to_s : BigDecimal(value.to_f.to_s).to_s("F")
|
46
|
-
re = /^(-?\d+)(\d\d\d)([_\.][_\.\d]+)?$/
|
47
|
-
while (m = re.match str)
|
48
|
-
str = "#{m[1]}_#{m[2]}#{m[3]}"
|
49
|
-
end
|
50
|
-
str
|
44
|
+
Gapic::FormattingUtils.format_number value
|
51
45
|
end
|
52
46
|
|
53
47
|
def assert_locals *locals
|
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.
|
4
|
+
version: 0.1.4
|
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-
|
13
|
+
date: 2020-03-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionpack
|
@@ -204,6 +204,7 @@ files:
|
|
204
204
|
- gem_templates/test_helper.erb
|
205
205
|
- gem_templates/version.erb
|
206
206
|
- lib/gapic/file_formatter.rb
|
207
|
+
- lib/gapic/formatting_utils.rb
|
207
208
|
- lib/gapic/gem_builder.rb
|
208
209
|
- lib/gapic/generator.rb
|
209
210
|
- lib/gapic/generator/version.rb
|