Method: Doing::Configuration#value_for_key

Defined in:
lib/doing/configuration.rb

#value_for_key(keypath = '') ⇒ Hash

Get the value for a fuzzy-matched key path

Parameters:

  • keypath (String) (defaults to: '')

    A dot-separated key path, e.g. "plugins.plugin_path". Will also work with "plug.path" (fuzzy matched, first match wins)

Returns:

  • (Hash)

    Config value



261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/doing/configuration.rb', line 261

def value_for_key(keypath = '')
  cfg = @settings
  real_path = ['config']
  unless keypath =~ /^[.*]?$/
    real_path = resolve_key_path(keypath, create: false)
    return nil unless real_path&.count&.positive?

    cfg = cfg.dig(*real_path)
  end

  cfg.nil? ? nil : { real_path[-1] => cfg }
end