Method: PDK::Config::Namespace#fetch

Defined in:
lib/pdk/config/namespace.rb

#fetch(key, default_value) ⇒ Object

Get the value of the named key or the provided default value if not present. Note that this does not trigger persistent defaults

This differs from #[] in an important way in that it allows you to return a default value, which is not possible using ‘[] || default` as non-existent values when accessed normally via #[] will be defaulted to a new Hash.

Parameters:

  • key (String, Symbol)

    the name of the value to fetch.

  • default_value (Object)

    the value to return if the namespace does not contain the requested value.

Returns:

  • (Object)

    the requested value.



123
124
125
126
127
128
129
130
# File 'lib/pdk/config/namespace.rb', line 123

def fetch(key, default_value)
  # Check if it's a mount first...
  return @mounts[key.to_s] unless @mounts[key.to_s].nil?
  # Check if it's a setting, otherwise default_value
  return default_value if settings[key.to_s].nil?
  # Check if has a value, otherwise default_value
  settings[key.to_s].value.nil? ? default_value : settings[key.to_s].value
end