Fixup macros

This commit is contained in:
Michael Miller 2022-03-05 15:39:19 -07:00
parent ac007f8565
commit d16c55984c
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF

View file

@ -68,10 +68,10 @@ module Spectator
if response if response
# Return configured response. # Return configured response.
response.as(Response(\{{NT[{{meth.name.symbolize}}]}})).value response.as(Response(\{{type}})).value
else else
# Response not configured for this method/message. # Response not configured for this method/message.
raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{meth.name}} with (<TODO: ARGS>).") raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
end end
\{% else %} \{% else %}
# Return type doesn't match configured type. # Return type doesn't match configured type.
@ -88,10 +88,10 @@ module Spectator
if response if response
# Return configured response. # Return configured response.
response.as(Response(\{{NT[{{meth.name.symbolize}}]}})).value response.as(Response(\{{type}})).value
else else
# Response not configured for this method/message. # Response not configured for this method/message.
raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{meth.name}} with (<TODO: ARGS>).") raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{meth.name}} (masking ancestor) with (<TODO: ARGS>).")
end end
{% end %} {% end %}
\{% else %} \{% else %}
@ -111,14 +111,14 @@ module Spectator
# Handle all methods but only respond to configured messages. # Handle all methods but only respond to configured messages.
# Raises an `UnexpectedMessage` error for non-configures messages. # Raises an `UnexpectedMessage` error for non-configures messages.
macro method_missing(call) macro method_missing(call)
\{% if NT.keys.includes?({{call.name.symbolize}}.id) %} \{% if type = NT[{{call.name.symbolize}}] %}
# Find a suitable response. # Find a suitable response.
call = MethodCall.capture({{call.name.symbolize}}, {{call.args.splat}}) call = MethodCall.capture({{call.name.symbolize}}, {{call.args.splat}})
response = @responses.find &.===(call) response = @responses.find &.===(call)
if response if response
# Return configured response. # Return configured response.
response.as(Response(\{{NT[{{call.name.symbolize}}]}})).value response.as(Response(\{{type}})).value
else else
# Response not configured for this method/message. # Response not configured for this method/message.
raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{call.name}} with (<TODO: ARGS>).") raise UnexpectedMessage.new("#{_spectator_double_name} received unexpected message :{{call.name}} with (<TODO: ARGS>).")