mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Clean up tags method generation by moving it to another macro
This commit is contained in:
parent
803a09464d
commit
e093ec788e
2 changed files with 50 additions and 60 deletions
|
@ -26,36 +26,8 @@ module Spectator::DSL
|
||||||
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
\{% raise "A description or block must be provided. Cannot use '{{name.id}}' alone." unless what || block %}
|
||||||
\{% 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
|
_spectator_tags_method(%tags, :_spectator_tags, {{tags.splat(",")}} {{metadata.double_splat}})
|
||||||
tags = _spectator_tags
|
_spectator_tags_method(\%tags, %tags, \{{tags.splat(",")}} \{{metadata.double_splat}})
|
||||||
{% if !tags.empty? %}
|
|
||||||
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
|
||||||
{% end %}
|
|
||||||
{% for k, v in metadata %}
|
|
||||||
cond = begin
|
|
||||||
{{v}}
|
|
||||||
end
|
|
||||||
if cond
|
|
||||||
tags.add({{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
tags.delete({{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
{% end %}
|
|
||||||
\{% if !tags.empty? %}
|
|
||||||
tags.concat({ \{{tags.map(&.id.symbolize).splat}} })
|
|
||||||
\{% end %}
|
|
||||||
\{% for k, v in metadata %}
|
|
||||||
cond = begin
|
|
||||||
\{{v}}
|
|
||||||
end
|
|
||||||
if cond
|
|
||||||
tags.add(\{{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
tags.delete(\{{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
\{% end %}
|
|
||||||
tags
|
|
||||||
end
|
|
||||||
|
|
||||||
def \%test(\{{block.args.splat}}) : Nil
|
def \%test(\{{block.args.splat}}) : Nil
|
||||||
\{{block.body}}
|
\{{block.body}}
|
||||||
|
@ -92,6 +64,29 @@ module Spectator::DSL
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Defines a class method named *name* that combines tags
|
||||||
|
# returned by *source* with *tags* and *metadata*.
|
||||||
|
# Any falsey items from *metadata* are removed.
|
||||||
|
private macro _spectator_tags_method(name, source, *tags, **metadata)
|
||||||
|
def self.{{name.id}}
|
||||||
|
tags = {{source.id}}
|
||||||
|
{% unless tags.empty? %}
|
||||||
|
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
||||||
|
{% end %}
|
||||||
|
{% for k, v in metadata %}
|
||||||
|
cond = begin
|
||||||
|
{{v}}
|
||||||
|
end
|
||||||
|
if cond
|
||||||
|
tags.add({{k.id.symbolize}})
|
||||||
|
else
|
||||||
|
tags.delete({{k.id.symbolize}})
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
define_example :example
|
define_example :example
|
||||||
|
|
||||||
define_example :it
|
define_example :it
|
||||||
|
|
|
@ -16,36 +16,8 @@ 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
|
_spectator_tags_method(:_spectator_tags, :super, {{tags.splat(", ")}} {{metadata.double_splat}})
|
||||||
tags = super
|
_spectator_tags_method(:_spectator_tags, :previous_def, \{{tags.splat(", ")}} \{{metadata.double_splat}})
|
||||||
{% if !tags.empty? %}
|
|
||||||
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
|
||||||
{% end %}
|
|
||||||
{% for k, v in metadata %}
|
|
||||||
cond = begin
|
|
||||||
{{v}}
|
|
||||||
end
|
|
||||||
if cond
|
|
||||||
tags.add({{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
tags.delete({{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
{% end %}
|
|
||||||
\{% if !tags.empty? %}
|
|
||||||
tags.concat({ \{{tags.map(&.id.symbolize).splat}} })
|
|
||||||
\{% end %}
|
|
||||||
\{% for k, v in metadata %}
|
|
||||||
cond = begin
|
|
||||||
\{{v}}
|
|
||||||
end
|
|
||||||
if cond
|
|
||||||
tags.add(\{{k.id.symbolize}})
|
|
||||||
else
|
|
||||||
tags.delete(\{{k.id.symbolize}})
|
|
||||||
end
|
|
||||||
\{% end %}
|
|
||||||
tags
|
|
||||||
end
|
|
||||||
|
|
||||||
::Spectator::DSL::Builder.start_group(
|
::Spectator::DSL::Builder.start_group(
|
||||||
_spectator_group_name(\{{what}}),
|
_spectator_group_name(\{{what}}),
|
||||||
|
@ -112,6 +84,29 @@ module Spectator::DSL
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Defines a class method named *name* that combines tags
|
||||||
|
# returned by *source* with *tags* and *metadata*.
|
||||||
|
# Any falsey items from *metadata* are removed.
|
||||||
|
private macro _spectator_tags_method(name, source, *tags, **metadata)
|
||||||
|
def self.{{name.id}}
|
||||||
|
tags = {{source.id}}
|
||||||
|
{% unless tags.empty? %}
|
||||||
|
tags.concat({ {{tags.map(&.id.symbolize).splat}} })
|
||||||
|
{% end %}
|
||||||
|
{% for k, v in metadata %}
|
||||||
|
cond = begin
|
||||||
|
{{v}}
|
||||||
|
end
|
||||||
|
if cond
|
||||||
|
tags.add({{k.id.symbolize}})
|
||||||
|
else
|
||||||
|
tags.delete({{k.id.symbolize}})
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
tags
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
define_example_group :example_group
|
define_example_group :example_group
|
||||||
|
|
||||||
define_example_group :describe
|
define_example_group :describe
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue