From 10b652f4b50f4420db8636a3da4358410a6a36af Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 31 Jul 2021 19:11:51 -0600 Subject: [PATCH] Remove unique/temp names --- src/spectator/events.cr | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/spectator/events.cr b/src/spectator/events.cr index 12f81a6..e77c61e 100644 --- a/src/spectator/events.cr +++ b/src/spectator/events.cr @@ -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