mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Don't need delegates stored in hooks
Use proc instead. The context can be retrieved from the example instance.
This commit is contained in:
parent
c4289b82da
commit
65dba9f317
2 changed files with 16 additions and 14 deletions
|
@ -1,9 +1,8 @@
|
|||
require "./context_delegate"
|
||||
require "./label"
|
||||
require "./source"
|
||||
|
||||
module Spectator
|
||||
# Information about a hook tied to an example group and a delegate to invoke it.
|
||||
# Information about a hook tied to an example group and a proc to invoke it.
|
||||
class ExampleGroupHook
|
||||
# Location of the hook in source code.
|
||||
getter! source : Source
|
||||
|
@ -11,22 +10,24 @@ module Spectator
|
|||
# User-defined description of the hook.
|
||||
getter! label : Label
|
||||
|
||||
# Creates the hook with a context delegate.
|
||||
# The *delegate* will be called when the hook is invoked.
|
||||
@proc : ->
|
||||
|
||||
# Creates the hook with a proc.
|
||||
# The *proc* will be called when the hook is invoked.
|
||||
# A *source* and *label* can be provided for debugging.
|
||||
def initialize(@delegate : ContextDelegate, *, @source : Source? = nil, @label : Label = nil)
|
||||
def initialize(@proc : (->), *, @source : Source? = nil, @label : Label = nil)
|
||||
end
|
||||
|
||||
# Creates the hook with a block.
|
||||
# The block will be executed when the hook is invoked.
|
||||
# A *source* and *label* can be provided for debugging.
|
||||
def initialize(*, @source : Source? = nil, @label : Label = nil, &block : -> _)
|
||||
@delegate = ContextDelegate.null(&block)
|
||||
@proc = block
|
||||
end
|
||||
|
||||
# Invokes the hook.
|
||||
def call : Nil
|
||||
@delegate.call
|
||||
@proc.call
|
||||
end
|
||||
|
||||
# Produces the string representation of the hook.
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
require "./example_context_delegate"
|
||||
require "./label"
|
||||
require "./source"
|
||||
|
||||
module Spectator
|
||||
# Information about a hook tied to an example and a delegate to invoke it.
|
||||
# Information about a hook tied to an example and a proc to invoke it.
|
||||
class ExampleHook
|
||||
# Location of the hook in source code.
|
||||
getter! source : Source
|
||||
|
@ -11,10 +10,12 @@ module Spectator
|
|||
# User-defined description of the hook.
|
||||
getter! label : Label
|
||||
|
||||
# Creates the hook with an example context delegate.
|
||||
# The *delegate* will be called when the hook is invoked.
|
||||
@proc : Example ->
|
||||
|
||||
# Creates the hook with a proc.
|
||||
# The *proc* will be called when the hook is invoked.
|
||||
# A *source* and *label* can be provided for debugging.
|
||||
def initialize(@delegate : ExampleContextDelegate, *, @source : Source? = nil, @label : Label = nil)
|
||||
def initialize(@proc : (Example ->), *, @source : Source? = nil, @label : Label = nil)
|
||||
end
|
||||
|
||||
# Creates the hook with a block.
|
||||
|
@ -22,13 +23,13 @@ module Spectator
|
|||
# The block will be executed when the hook is invoked.
|
||||
# A *source* and *label* can be provided for debugging.
|
||||
def initialize(*, @source : Source? = nil, @label : Label = nil, &block : Example -> _)
|
||||
@delegate = ExampleContextDelegate.null(&block)
|
||||
@proc = block
|
||||
end
|
||||
|
||||
# Invokes the hook.
|
||||
# The *example* refers to the current example.
|
||||
def call(example : Example) : Nil
|
||||
@delegate.call(example)
|
||||
@proc.call(example)
|
||||
end
|
||||
|
||||
# Produces the string representation of the hook.
|
||||
|
|
Loading…
Reference in a new issue