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