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 %}
def self.\%tags
\{% if tags.empty? && metadata.empty? %}
_spectator_tags
\{% else %}
_spectator_tags.concat({\{{tags.map(&.id.stringify).splat}}}).tap do |tags|
tags = _spectator_tags
\{% if !tags.empty? %}
tags.concat({ \{{tags.map(&.id.stringify).splat}} })
\{% end %}
\{% for k, v in metadata %}
cond = begin
\{{v}}
@ -38,11 +38,10 @@ module Spectator::DSL
if cond
tags.add(\{{k.id.stringify}})
else
tags.remove(\{{k.id.stringify}})
end
\{% end %}
tags.delete(\{{k.id.stringify}})
end
\{% end %}
tags
end
def \%test(\{{block.args.splat}}) : Nil

View file

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