mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Obscure and disallow double name method
This commit is contained in:
parent
5644d54470
commit
9594604770
2 changed files with 14 additions and 13 deletions
|
@ -9,6 +9,6 @@ module Spectator
|
|||
module DSL
|
||||
# Keywords that cannot be used in specs using the DSL.
|
||||
# These are either problematic or reserved for internal use.
|
||||
RESERVED_KEYWORDS = %i[initialize]
|
||||
RESERVED_KEYWORDS = %i[initialize _spectator_double_name]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,15 @@ module Spectator
|
|||
def initialize(@name : String? = nil, **@messages : **Messages)
|
||||
end
|
||||
|
||||
# Utility returning the double's name as a string.
|
||||
private def _spectator_double_name : String
|
||||
if name = @name
|
||||
"\"#{name}\""
|
||||
else
|
||||
"Anonymous"
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Define macro to redefine a type's method.
|
||||
# TODO: Better error for type mismatch
|
||||
macro finished
|
||||
|
@ -27,7 +36,7 @@ module Spectator
|
|||
@messages[{{meth.name.symbolize}}]
|
||||
{% end %}
|
||||
\{% else %}
|
||||
raise UnexpectedMessage.new("Double<#{_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
raise UnexpectedMessage.new("Double<#{_spectator_double_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
\{% end %}
|
||||
end
|
||||
{% end %}
|
||||
|
@ -52,7 +61,7 @@ module Spectator
|
|||
@messages[{{meth.name.symbolize}}]
|
||||
{% end %}
|
||||
\{% else %}
|
||||
raise UnexpectedMessage.new("Double<#{_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
raise UnexpectedMessage.new("Double<#{_spectator_double_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
\{% end %}
|
||||
end
|
||||
{% end %}
|
||||
|
@ -77,26 +86,18 @@ module Spectator
|
|||
@messages[{{meth.name.symbolize}}]
|
||||
{% end %}
|
||||
\{% else %}
|
||||
raise UnexpectedMessage.new("Double<#{_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
raise UnexpectedMessage.new("Double<#{_spectator_double_name}> received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
|
||||
\{% end %}
|
||||
end
|
||||
{% end %}
|
||||
{% end %}
|
||||
|
||||
private def _name
|
||||
if name = @name
|
||||
"\"#{name}\""
|
||||
else
|
||||
"Anonymous"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
macro method_missing(call)
|
||||
\{% if Messages.keys.includes?({{call.name.symbolize}}.id) %}
|
||||
@messages[{{call.name.symbolize}}]
|
||||
\{% else %}
|
||||
raise UnexpectedMessage.new("Double<#{_name}> received unexpected message :{{call.name}} with (<TODO: ARGS>).")
|
||||
raise UnexpectedMessage.new("Double<#{_spectator_double_name}> received unexpected message :{{call.name}} with (<TODO: ARGS>).")
|
||||
\{% end %}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue