Class: Meta::Utils::Kwargs::Checker
- Inherits:
-
Object
- Object
- Meta::Utils::Kwargs::Checker
- Defined in:
- lib/meta/utils/kwargs/checker.rb
Instance Attribute Summary collapse
-
#arguments_consumer ⇒ Object
readonly
Returns the value of attribute arguments_consumer.
Instance Method Summary collapse
- #check(args, extras_handler: nil) ⇒ Object
-
#initialize(arguments_consumer:, extras_consumer: nil, after_handler: nil) ⇒ Checker
constructor
A new instance of Checker.
Constructor Details
#initialize(arguments_consumer:, extras_consumer: nil, after_handler: nil) ⇒ Checker
Returns a new instance of Checker.
9 10 11 12 13 |
# File 'lib/meta/utils/kwargs/checker.rb', line 9 def initialize(arguments_consumer:, extras_consumer: nil, after_handler: nil) @arguments_consumer = arguments_consumer @extras_consumer = extras_consumer || ExtrasConsumers::RaiseError @after_handler = after_handler end |
Instance Attribute Details
#arguments_consumer ⇒ Object (readonly)
Returns the value of attribute arguments_consumer.
7 8 9 |
# File 'lib/meta/utils/kwargs/checker.rb', line 7 def arguments_consumer @arguments_consumer end |
Instance Method Details
#check(args, extras_handler: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/meta/utils/kwargs/checker.rb', line 15 def check(args, extras_handler: nil) # 准备工作 args = args.dup final_args = {} # 逐个消费参数 @arguments_consumer.consume(final_args, args) # 处理额外参数 extras_consumer = ExtrasConsumers.resolve_handle_extras(extras_handler) extras_consumer ||= @extras_consumer extras_consumer&.consume(final_args, args) # 后置处理器 @after_handler&.call(final_args) # 返回最终参数 final_args end |