mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move method masking macro to Stubable
Rename to stub_all.
This commit is contained in:
parent
85cc28c499
commit
56f1c77a6c
2 changed files with 15 additions and 15 deletions
|
@ -43,23 +43,9 @@ module Spectator
|
|||
{% end %}
|
||||
end
|
||||
|
||||
# Redefines all methods on a type to conditionally respond to messages.
|
||||
# Methods will raise `UnexpectedMessage` if they're called when they shouldn't be.
|
||||
# Otherwise, they'll return the configured response.
|
||||
private macro _spectator_mask_methods(type_name)
|
||||
{% type = type_name.resolve %}
|
||||
{% if type.superclass %}
|
||||
_spectator_mask_methods({{type.superclass}})
|
||||
{% end %}
|
||||
|
||||
{% for meth in type.methods.reject { |m| DSL::RESERVED_KEYWORDS.includes?(m.name.symbolize) } %}
|
||||
abstract_stub {{meth}}
|
||||
{% end %}
|
||||
end
|
||||
|
||||
# "Hide" existing methods and methods from ancestors by overriding them.
|
||||
macro finished
|
||||
_spectator_mask_methods({{@type.name(generic_args: false)}})
|
||||
stub_all {{@type.name(generic_args: false)}}
|
||||
end
|
||||
|
||||
# Handle all methods but only respond to configured messages.
|
||||
|
|
|
@ -76,5 +76,19 @@ module Spectator
|
|||
{{method}}
|
||||
stub {{method}}
|
||||
end
|
||||
|
||||
# Redefines all methods on a type to conditionally respond to messages.
|
||||
# Methods will raise `UnexpectedMessage` if they're called when they shouldn't be.
|
||||
# Otherwise, they'll return the configured response.
|
||||
private macro stub_all(type_name, *, with style = :abstract_stub)
|
||||
{% type = type_name.resolve %}
|
||||
{% if type.superclass %}
|
||||
stub_all({{type.superclass}}, with: {{style}})
|
||||
{% end %}
|
||||
|
||||
{% for meth in type.methods.reject { |m| DSL::RESERVED_KEYWORDS.includes?(m.name.symbolize) } %}
|
||||
{{style.id}} {{meth}}
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue