Fix case with no tags and some metadata

Simplify tag set construction code.
This commit is contained in:
Michael Miller 2021-01-30 12:01:49 -07:00
parent 467f0d3ad4
commit 5166cd7778
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 32 additions and 32 deletions

View file

@ -27,10 +27,10 @@ module Spectator::DSL
\{% raise "Block argument count '{{name.id}}' hook must be 0..1" if block.args.size > 1 %} \{% raise "Block argument count '{{name.id}}' hook must be 0..1" if block.args.size > 1 %}
def self.\%tags def self.\%tags
\{% if tags.empty? && metadata.empty? %} tags = _spectator_tags
_spectator_tags \{% if !tags.empty? %}
\{% else %} tags.concat({ \{{tags.map(&.id.stringify).splat}} })
_spectator_tags.concat({\{{tags.map(&.id.stringify).splat}}}).tap do |tags| \{% end %}
\{% for k, v in metadata %} \{% for k, v in metadata %}
cond = begin cond = begin
\{{v}} \{{v}}
@ -38,11 +38,10 @@ module Spectator::DSL
if cond if cond
tags.add(\{{k.id.stringify}}) tags.add(\{{k.id.stringify}})
else else
tags.remove(\{{k.id.stringify}}) tags.delete(\{{k.id.stringify}})
end
\{% end %}
end end
\{% end %} \{% end %}
tags
end end
def \%test(\{{block.args.splat}}) : Nil def \%test(\{{block.args.splat}}) : Nil

View file

@ -16,11 +16,12 @@ module Spectator::DSL
class Group\%group < \{{@type.id}} class Group\%group < \{{@type.id}}
_spectator_group_subject(\{{what}}) _spectator_group_subject(\{{what}})
\{% if !tags.empty? || !metadata.empty? %}
def self._spectator_tags def self._spectator_tags
\{% if tags.empty? && metadata.empty? %} tags = super
super \{% if !tags.empty? %}
\{% else %} tags.concat({ \{{tags.map(&.id.stringify).splat}} })
super.concat({\{{tags.map(&.id.stringify).splat}}}).tap do |tags| \{% end %}
\{% for k, v in metadata %} \{% for k, v in metadata %}
cond = begin cond = begin
\{{v}} \{{v}}
@ -28,12 +29,12 @@ module Spectator::DSL
if cond if cond
tags.add(\{{k.id.stringify}}) tags.add(\{{k.id.stringify}})
else else
tags.remove(\{{k.id.stringify}}) tags.delete(\{{k.id.stringify}})
end end
\{% end %} \{% end %}
tags
end end
\{% end %} \{% end %}
end
::Spectator::DSL::Builder.start_group( ::Spectator::DSL::Builder.start_group(
_spectator_group_name(\{{what}}), _spectator_group_name(\{{what}}),