Module: Nero::DigExt

Included in:
Config
Defined in:
lib/nero.rb

Instance Method Summary collapse

Instance Method Details

#dig!(*path) ⇒ Object

⛏️💥 Like dig, but raises ArgumentError when path does not exist.

Examples:

like dig

{a: {b: 2}}.dig!(:a, :b) #=> 2
{a: {b: 2}}.dig!(:a, :c) #=> ArgumentError, path not found [:a, :c] (ArgumentError)

Parameters:

  • path

    nested keys into config

Raises:

  • (ArgumentError)

    when path does not exist.



26
27
28
29
30
31
32
33
# File 'lib/nero.rb', line 26

def dig!(k0, *k)
  k.unshift(k0)

  unless paths.include?(k)
    raise ArgumentError, "path not found #{k}"
  end
  dig(*k)
end