shard-spectator/src/spectator/dsl/metadata.cr

30 lines
875 B
Crystal
Raw Normal View History

2021-01-30 22:34:17 +00:00
module Spectator::DSL
module Metadata
# Defines a class method named *name* that combines metadata
2021-01-30 22:34:17 +00:00
# returned by *source* with *tags* and *metadata*.
# Any falsey items from *metadata* are removed.
private macro _spectator_metadata(name, source, *tags, **metadata)
2021-02-10 05:40:15 +00:00
private def self.{{name.id}}
%metadata = {{source.id}}.dup
2022-11-30 06:22:42 +00:00
{% unless tags.empty? && metadata.empty? %}
%metadata ||= ::Spectator::Metadata.new
{% end %}
{% for k in tags %}
%metadata[{{k.id.symbolize}}] = nil
2021-01-30 22:34:17 +00:00
{% end %}
{% for k, v in metadata %}
%cond = begin
{{v}}
end
if %cond
%metadata[{{k.id.symbolize}}] = %cond.to_s
2021-01-30 22:34:17 +00:00
else
%metadata.delete({{k.id.symbolize}})
2021-01-30 22:34:17 +00:00
end
{% end %}
%metadata
2021-01-30 22:34:17 +00:00
end
end
end
end