Module: Olyx::Guardrails::Notification::HandlerCollectionValidator

Defined in:
lib/olyx/guardrails/notification/handler_collection_validator.rb

Overview

Validates handler collection shape and normalized-name uniqueness.

Class Method Summary collapse

Class Method Details

.input!(handlers, maximum:) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib/olyx/guardrails/notification/handler_collection_validator.rb', line 10

def input!(handlers, maximum:)
  return if handlers.is_a?(Hash) && !handlers.empty? && handlers.length <= maximum

  raise ArgumentError, "handlers must be a non-empty Hash with at most #{maximum} entries"
end

.unique!(handlers) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
# File 'lib/olyx/guardrails/notification/handler_collection_validator.rb', line 16

def unique!(handlers)
  names = handlers.map(&:first)
  raise ArgumentError, 'handler names must be unique' unless names.uniq.length == names.length
end