Class: Configurations::Validators::Ambiguity

Inherits:
Object
  • Object
show all
Defined in:
lib/configurations/validators/ambiguity.rb

Instance Method Summary collapse

Instance Method Details

#validate!(h) ⇒ Object

Parameters:

  • the (Hash)

    hash to test for ambiguity

Raises:


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/configurations/validators/ambiguity.rb', line 8

def validate!(h)
  symbols, others = h.keys.partition { |k|
    k.is_a?(::Symbol)
  }

  ambiguous = symbols.map(&:to_s) & others

  unless ambiguous.empty?
    ::Kernel.fail(
      ::Configurations::ConfigurationError,
      "Can not resolve configuration values for #{ambiguous.join(', ')} " \
      "defined as both Symbol and #{others.first.class.name} keys. " \
      'Please resolve the ambiguity.'
    )
  end
end