Module: Polyrun::Config::DottedPath

Defined in:
lib/polyrun/config/dotted_path.rb

Overview

Read nested keys from loaded YAML (String / Symbol indifferent at each step).

Class Method Summary collapse

Class Method Details

.dig(raw, dotted) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/polyrun/config/dotted_path.rb', line 7

def dig(raw, dotted)
  segments = dotted.split(".")
  return nil if segments.empty?
  return nil if segments.any?(&:empty?)

  segments.reduce(raw) do |m, seg|
    break nil if m.nil?
    break nil unless m.is_a?(Hash)

    m[seg] || m[seg.to_sym]
  end
end