Class: Sequent::Core::Helpers::MessageHandler::OnArgumentsValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/core/helpers/message_handler.rb

Class Method Summary collapse

Class Method Details

.validate_arguments!(*args) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sequent/core/helpers/message_handler.rb', line 76

def validate_arguments!(*args)
  fail ArgumentError, "Must provide at least one argument to 'on'" if args.empty?

  duplicates = args
    .select { |arg| args.count(arg) > 1 }
    .uniq

  if duplicates.any?
    humanized_duplicates = duplicates
      .map { |x| MessageMatchers::ArgumentSerializer.serialize_value(x) }
      .join(', ')

    fail ArgumentError,
         "Arguments to 'on' must be unique, duplicates: #{humanized_duplicates}"
  end
end