mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove unique/temp names
This commit is contained in:
parent
3dc3b88dbe
commit
10b652f4b5
1 changed files with 12 additions and 12 deletions
|
@ -25,18 +25,18 @@ module Spectator
|
|||
# end
|
||||
# ```
|
||||
private macro group_event(name, &block)
|
||||
@%hooks = [] of ExampleGroupHook
|
||||
@%called = Atomic::Flag.new
|
||||
@{{name.id}}_hooks = [] of ExampleGroupHook
|
||||
@{{name.id}}_called = Atomic::Flag.new
|
||||
|
||||
# Adds a hook to be invoked when the *{{name.id}}* event occurs.
|
||||
def add_{{name.id}}_hook(hook : ExampleGroupHook) : Nil
|
||||
@%hooks << hook
|
||||
@{{name.id}}_hooks << hook
|
||||
end
|
||||
|
||||
# Adds a hook to be invoked when the *{{name.id}}* event occurs.
|
||||
# The hook is added to the front of the list.
|
||||
def prepend_{{name.id}}_hook(hook : ExampleGroupHook) : Nil
|
||||
@%hooks.unshift(hook)
|
||||
@{{name.id}}_hooks.unshift(hook)
|
||||
end
|
||||
|
||||
# Defines a hook for the *{{name.id}}* event.
|
||||
|
@ -49,20 +49,20 @@ module Spectator
|
|||
# Signals that the *{{name.id}}* event has occurred.
|
||||
# All hooks associated with the event will be called.
|
||||
def call_{{name.id}} : Nil
|
||||
%block(@%hooks)
|
||||
handle_{{name.id}}(@{{name.id}}_hooks)
|
||||
end
|
||||
|
||||
# Signals that the *{{name.id}}* event has occurred.
|
||||
# Only calls the hooks if the event hasn't been triggered before by this method.
|
||||
# Returns true if the hooks were called and false if they weren't (called previously).
|
||||
def call_once_{{name.id}} : Bool
|
||||
first = @%called.test_and_set
|
||||
first = @{{name.id}}_called.test_and_set
|
||||
call_{{name.id}} if first
|
||||
first
|
||||
end
|
||||
|
||||
# Logic specific to invoking the *{{name.id}}* hook.
|
||||
private def %block({{block.args.splat}})
|
||||
private def handle_{{name.id}}({{block.args.splat}})
|
||||
{{block.body}}
|
||||
end
|
||||
end
|
||||
|
@ -85,17 +85,17 @@ module Spectator
|
|||
# end
|
||||
# ```
|
||||
private macro example_event(name, &block)
|
||||
@%hooks = [] of ExampleHook
|
||||
@{{name.id}}_hooks = [] of ExampleHook
|
||||
|
||||
# Adds a hook to be invoked when the *{{name.id}}* event occurs.
|
||||
def add_{{name.id}}_hook(hook : ExampleHook) : Nil
|
||||
@%hooks << hook
|
||||
@{{name.id}}_hooks << hook
|
||||
end
|
||||
|
||||
# Adds a hook to be invoked when the *{{name.id}}* event occurs.
|
||||
# The hook is added to the front of the list.
|
||||
def prepend_{{name.id}}_hook(hook : ExampleHook) : Nil
|
||||
@%hooks.unshift(hook)
|
||||
@{{name.id}}_hooks.unshift(hook)
|
||||
end
|
||||
|
||||
# Defines a hook for the *{{name.id}}* event.
|
||||
|
@ -110,11 +110,11 @@ module Spectator
|
|||
# All hooks associated with the event will be called.
|
||||
# The *example* should be the current example.
|
||||
def call_{{name.id}}(example : Example) : Nil
|
||||
%block(@%hooks, example)
|
||||
handle_{{name.id}}(@{{name.id}}_hooks, example)
|
||||
end
|
||||
|
||||
# Logic specific to invoking the *{{name.id}}* hook.
|
||||
private def %block({{block.args.splat}})
|
||||
private def handle_{{name.id}}({{block.args.splat}})
|
||||
{{block.body}}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue