2021-01-30 22:34:17 +00:00
|
|
|
module Spectator::DSL
|
2021-06-12 22:45:45 +00:00
|
|
|
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.
|
2021-06-12 22:45:45 +00:00
|
|
|
private macro _spectator_metadata(name, source, *tags, **metadata)
|
2021-02-10 05:40:15 +00:00
|
|
|
private def self.{{name.id}}
|
2021-06-12 22:45:45 +00:00
|
|
|
%metadata = {{source.id}}.dup
|
2022-11-30 06:22:42 +00:00
|
|
|
{% unless tags.empty? && metadata.empty? %}
|
|
|
|
%metadata ||= ::Spectator::Metadata.new
|
|
|
|
{% end %}
|
2021-06-12 00:26:55 +00:00
|
|
|
{% for k in tags %}
|
2021-06-12 22:45:45 +00:00
|
|
|
%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
|
2021-06-12 22:45:45 +00:00
|
|
|
%metadata[{{k.id.symbolize}}] = %cond.to_s
|
2021-01-30 22:34:17 +00:00
|
|
|
else
|
2021-06-12 22:45:45 +00:00
|
|
|
%metadata.delete({{k.id.symbolize}})
|
2021-01-30 22:34:17 +00:00
|
|
|
end
|
|
|
|
{% end %}
|
2021-06-12 22:45:45 +00:00
|
|
|
%metadata
|
2021-01-30 22:34:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|