Remove unique/temp names

This commit is contained in:
Michael Miller 2021-07-31 19:11:51 -06:00
parent 3dc3b88dbe
commit 10b652f4b5
No known key found for this signature in database
GPG key ID: F9A0C5C65B162436

View file

@ -25,18 +25,18 @@ module Spectator
# end # end
# ``` # ```
private macro group_event(name, &block) private macro group_event(name, &block)
@%hooks = [] of ExampleGroupHook @{{name.id}}_hooks = [] of ExampleGroupHook
@%called = Atomic::Flag.new @{{name.id}}_called = Atomic::Flag.new
# Adds a hook to be invoked when the *{{name.id}}* event occurs. # Adds a hook to be invoked when the *{{name.id}}* event occurs.
def add_{{name.id}}_hook(hook : ExampleGroupHook) : Nil def add_{{name.id}}_hook(hook : ExampleGroupHook) : Nil
@%hooks << hook @{{name.id}}_hooks << hook
end end
# Adds a hook to be invoked when the *{{name.id}}* event occurs. # Adds a hook to be invoked when the *{{name.id}}* event occurs.
# The hook is added to the front of the list. # The hook is added to the front of the list.
def prepend_{{name.id}}_hook(hook : ExampleGroupHook) : Nil def prepend_{{name.id}}_hook(hook : ExampleGroupHook) : Nil
@%hooks.unshift(hook) @{{name.id}}_hooks.unshift(hook)
end end
# Defines a hook for the *{{name.id}}* event. # Defines a hook for the *{{name.id}}* event.
@ -49,20 +49,20 @@ module Spectator
# Signals that the *{{name.id}}* event has occurred. # Signals that the *{{name.id}}* event has occurred.
# All hooks associated with the event will be called. # All hooks associated with the event will be called.
def call_{{name.id}} : Nil def call_{{name.id}} : Nil
%block(@%hooks) handle_{{name.id}}(@{{name.id}}_hooks)
end end
# Signals that the *{{name.id}}* event has occurred. # Signals that the *{{name.id}}* event has occurred.
# Only calls the hooks if the event hasn't been triggered before by this method. # 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). # Returns true if the hooks were called and false if they weren't (called previously).
def call_once_{{name.id}} : Bool def call_once_{{name.id}} : Bool
first = @%called.test_and_set first = @{{name.id}}_called.test_and_set
call_{{name.id}} if first call_{{name.id}} if first
first first
end end
# Logic specific to invoking the *{{name.id}}* hook. # Logic specific to invoking the *{{name.id}}* hook.
private def %block({{block.args.splat}}) private def handle_{{name.id}}({{block.args.splat}})
{{block.body}} {{block.body}}
end end
end end
@ -85,17 +85,17 @@ module Spectator
# end # end
# ``` # ```
private macro example_event(name, &block) 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. # Adds a hook to be invoked when the *{{name.id}}* event occurs.
def add_{{name.id}}_hook(hook : ExampleHook) : Nil def add_{{name.id}}_hook(hook : ExampleHook) : Nil
@%hooks << hook @{{name.id}}_hooks << hook
end end
# Adds a hook to be invoked when the *{{name.id}}* event occurs. # Adds a hook to be invoked when the *{{name.id}}* event occurs.
# The hook is added to the front of the list. # The hook is added to the front of the list.
def prepend_{{name.id}}_hook(hook : ExampleHook) : Nil def prepend_{{name.id}}_hook(hook : ExampleHook) : Nil
@%hooks.unshift(hook) @{{name.id}}_hooks.unshift(hook)
end end
# Defines a hook for the *{{name.id}}* event. # Defines a hook for the *{{name.id}}* event.
@ -110,11 +110,11 @@ module Spectator
# All hooks associated with the event will be called. # All hooks associated with the event will be called.
# The *example* should be the current example. # The *example* should be the current example.
def call_{{name.id}}(example : Example) : Nil def call_{{name.id}}(example : Example) : Nil
%block(@%hooks, example) handle_{{name.id}}(@{{name.id}}_hooks, example)
end end
# Logic specific to invoking the *{{name.id}}* hook. # Logic specific to invoking the *{{name.id}}* hook.
private def %block({{block.args.splat}}) private def handle_{{name.id}}({{block.args.splat}})
{{block.body}} {{block.body}}
end end
end end