Skip to content

Commit d6edb6e

Browse files
Fix bug in display of all extensions that define a parameter in a CRD.
1 parent 6e40ed8 commit d6edb6e

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

backends/manual/templates/param_list.adoc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The following <%= params.size %> parameters are defined in this manual:
1212
<%- params.each do |param| -%>
1313
| <%= param.name %>
1414
| <%= param.schema.to_pretty_s %>
15-
| <%= param.exts.map { |ext| link_to_udb_doc_ext_param(ext.name, param.name) }.join(", ") %>
15+
| <%= param.exts.map { |ext| link_to_udb_doc_ext_param(ext.name, param.name, ext.name) }.join(", ") %>
1616
a| <%= param.desc %>
1717
<%- end -%>
1818
|===

backends/portfolio/templates/coverage_points.adoc.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Coverage Points for `<%= nice_name %>`: ::
88

99
[%autowidth]
1010
|===
11-
| ID | Name | Description | Links
11+
| ID | Name | Description | Documentation Links
1212

1313
<% db_obj.cert_coverage_points.each do |cp| -%>
1414
| <%= defined?(org) ? anchor_for_udb_cert_cov_pt(org, cp.id) : "" %><%= cp.id %>

backends/proc_crd/templates/proc_crd.adoc.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ None
235235
| <%= param.name_potentially_with_link(in_scope_exts) %>
236236
| <%= param.schema_type %>
237237
| <%= in_scope_param.allowed_values %>
238-
| <%= in_scope_exts.each { |ext| param.name_with_link(ext) } %>
238+
| <%= in_scope_exts.map { |ext| link_to_udb_doc_ext_param(ext.name, param.name, ext.name) }.join(", ") %>
239239
a| <%= in_scope_param.note %>
240240
<% end # do -%>
241241
|===
@@ -258,7 +258,7 @@ None
258258
<% exts = portfolio_design.all_in_scope_exts_without_param(param) -%>
259259
| <%= param.name_potentially_with_link(exts) %>
260260
| <%= param.schema_type %>
261-
| <%= exts.each { |ext| param.name_with_link(ext) } %>
261+
| <%= exts.map { |ext| link_to_udb_doc_ext_param(ext.name, param.name, ext.name) }.join(", ") %>
262262
263263
<% end # do -%>
264264
|===

lib/arch_obj_models/parameter.rb

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,39 @@ def schema_type
4040
# @param name [String]
4141
# @param data [Hash<String, Object]
4242
def initialize(ext, name, data)
43+
raise ArgumentError, "Expecting Extension but got #{ext.class}" unless ext.is_a?(Extension)
44+
raise ArgumentError, "Expecting String but got #{name.class}" unless name.is_a?(String)
45+
raise ArgumentError, "Expecting Hash but got #{data.class}" unless data.is_a?(Hash)
46+
4347
@arch = ext.arch
4448
@data = data
4549
@name = name
4650
@desc = data["description"]
4751
@schema = Schema.new(data["schema"])
4852
@extra_validation = data["extra_validation"]
49-
also_defined_in = []
50-
unless data["also_defined_in"].nil?
51-
if data["also_defined_in"].is_a?(String)
52-
other_ext = @arch.extension(data["also_defined_in"])
53-
raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil?
54-
55-
also_defined_in << other_ext
53+
also_defined_in_array = []
54+
also_defined_in_data = data["also_defined_in"]
55+
unless also_defined_in_data.nil?
56+
if also_defined_in_data.is_a?(String)
57+
other_ext_name = also_defined_in_data
58+
other_ext = @arch.extension(other_ext_name)
59+
raise "Definition error in #{ext.name}.#{name}: #{other_ext_name} is not a known extension" if other_ext.nil?
60+
61+
also_defined_in_array << other_ext
5662
else
57-
unless data["also_defined_in"].is_a?(Array) && data["also_defined_in"].all? { |e| e.is_a?(String) }
63+
unless also_defined_in_data.is_a?(Array) && also_defined_in_data.all? { |e| e.is_a?(String) }
5864
raise "schema error: also_defined_in should be a string or array of strings"
5965
end
6066

61-
data["also_defined_in"].each do |other_ext_name|
67+
also_defined_in_data.each do |other_ext_name|
6268
other_ext = @arch.extension(other_ext_name)
63-
raise "Definition error in #{ext.name}.#{name}: #{data['also_defined_in']} is not a known extension" if other_ext.nil?
69+
raise "Definition error in #{ext.name}.#{name}: #{also_defined_in_data} is not a known extension" if other_ext.nil?
6470

65-
also_defined_in << other_ext
71+
also_defined_in_array << other_ext
6672
end
6773
end
6874
end
69-
@exts = [ext] + also_defined_in
75+
@exts = [ext] + also_defined_in_array
7076
@idl_type = @schema.to_idl_type.make_const.freeze
7177
end
7278

@@ -81,22 +87,15 @@ def defined_in_extension_version?(version)
8187
end
8288
end
8389

84-
# @param ext [Extension] Extension that defines this parameter.
85-
# @return [String] Text that includes the parameter name and a link to the parameter definition.
86-
# Should only be called if there is only one in-scope extension that defines the parameter.
87-
def name_with_link(ext)
88-
link_to_udb_doc_ext_param(ext.name, name)
89-
end
90-
9190
# @param exts [Array<Extension>] List of all in-scope extensions that define this parameter.
92-
# @return [String] Text that includes the parameter name and a link to the parameter definition
91+
# @return [String] Text to create a link to the parameter definition with the link text the parameter name.
9392
# if only one extension defines the parameter, otherwise just the parameter name.
9493
def name_potentially_with_link(in_scope_exts)
95-
raise ArgumentError, "Expecting Array" unless in_scope_exts.is_a?(Array)
94+
raise ArgumentError, "Expecting Array but got #{in_scope_exts.class}" unless in_scope_exts.is_a?(Array)
9695
raise ArgumentError, "Expecting Array[Extension]" unless in_scope_exts[0].is_a?(Extension)
9796

9897
if in_scope_exts.size == 1
99-
link_to_udb_doc_ext_param(in_scope_exts[0].name, name)
98+
link_to_udb_doc_ext_param(in_scope_exts[0].name, name, name)
10099
else
101100
name
102101
end

lib/backend_helpers.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ def link_to_udb_doc_ext(ext_name)
5656
# @return [String] A hyperlink to UDB parameter documentation
5757
# @param ext_name [String] Name of the extension
5858
# @param param_name [String] Name of the parameter
59-
def link_to_udb_doc_ext_param(ext_name, param_name)
59+
# @param link_text [String] What to put in the link text (don't assume param_name)
60+
def link_to_udb_doc_ext_param(ext_name, param_name, link_text)
6061
check_no_periods(param_name)
61-
"%%UDB_DOC_LINK%ext_param;#{ext_name.sanitize}.#{param_name};#{param_name}%%"
62+
"%%UDB_DOC_LINK%ext_param;#{ext_name.sanitize}.#{param_name};#{link_text}%%"
6263
end
6364

6465
# @return [String] A hyperlink to UDB instruction documentation

lib/test/test_backend_helpers.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ def test_ext
1717
end
1818

1919
def test_ext_param
20-
assert_equal("%%UDB_DOC_LINK%ext_param;foo.bar;bar%%", link_to_udb_doc_ext_param("foo","bar"))
20+
assert_equal("%%UDB_DOC_LINK%ext_param;foo.bar;zort%%", link_to_udb_doc_ext_param("foo","bar","zort"))
2121
assert_equal("[#udb:doc:ext_param:foo:bar]", anchor_for_udb_doc_ext_param("foo","bar"))
22-
assert_equal("%%UDB_DOC_LINK%ext_param;fo_o.bar;bar%%", link_to_udb_doc_ext_param("fo.o","bar"))
22+
assert_equal("%%UDB_DOC_LINK%ext_param;fo_o.bar;fluffy%%", link_to_udb_doc_ext_param("fo.o","bar","fluffy"))
2323
assert_equal("[#udb:doc:ext_param:fo_o:bar]", anchor_for_udb_doc_ext_param("fo.o","bar"))
24-
assert_raises(ArgumentError) { link_to_udb_doc_ext_param("foo","ba.r") }
24+
assert_raises(ArgumentError) { link_to_udb_doc_ext_param("foo","ba.r","fluffy") }
2525
assert_raises(ArgumentError) { anchor_for_udb_doc_ext_param("foo","ba.r") }
2626
end
2727

@@ -77,7 +77,7 @@ def test_resolve_links_ext
7777

7878
def test_resolve_links_ext_param
7979
assert_equal("<<udb:doc:ext_param:foo:bar,zort>>", AsciidocUtils.resolve_links("%%UDB_DOC_LINK%ext_param;foo.bar;zort%%"))
80-
assert_equal("<<udb:doc:ext_param:foo:bar,bar>>", AsciidocUtils.resolve_links(link_to_udb_doc_ext_param("foo","bar")))
80+
assert_equal("<<udb:doc:ext_param:foo:bar,bob>>", AsciidocUtils.resolve_links(link_to_udb_doc_ext_param("foo","bar","bob")))
8181
end
8282

8383
def test_resolve_links_inst
@@ -121,7 +121,7 @@ def test_resolve_links_ext
121121

122122
def test_resolve_links_ext_param
123123
assert_equal("xref:exts:foo.adoc#udb:doc:ext_param:foo:bar[[zort\\]]", AntoraUtils.resolve_links("%%UDB_DOC_LINK%ext_param;foo.bar;[zort]%%"))
124-
assert_equal("xref:exts:foo.adoc#udb:doc:ext_param:foo:bar[bar]", AntoraUtils.resolve_links(link_to_udb_doc_ext_param("foo","bar")))
124+
assert_equal("xref:exts:foo.adoc#udb:doc:ext_param:foo:bar[bob]", AntoraUtils.resolve_links(link_to_udb_doc_ext_param("foo","bar","bob")))
125125
end
126126

127127
def test_resolve_links_inst

0 commit comments

Comments
 (0)