Module: Meta::Utils::Kwargs::ExtrasConsumers

Defined in:
lib/meta/utils/kwargs/extras_consumers.rb

Constant Summary collapse

Ignore =
ProcConsumer.new
Merged =
ProcConsumer.new do |final_args, args|
  final_args.merge!(args)
end
RaiseError =
ProcConsumer.new do |final_args, args|
  extras_keys = args.keys
  raise ArgumentError, "不接受额外的关键字参数:#{extras_keys.join(', ')}" unless extras_keys.empty?
end

Class Method Summary collapse

Class Method Details

.resolve_handle_extras(sym) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/meta/utils/kwargs/extras_consumers.rb', line 16

def self.resolve_handle_extras(sym)
  return nil if sym.nil?

  case sym
  when :ignore
    ExtrasConsumers::Ignore
  when :merged
    ExtrasConsumers::Merged
  when :raise_error
    ExtrasConsumers::RaiseError
  else
    raise ArgumentError, "handle_extras 只接受 :ignore, :merged, :raise_error 三种值,当前传递:#{sym}"
  end
end