Method: PDK::Config#set

Defined in:
lib/pdk/config.rb

#set(key, value, options = {}) ⇒ Object

Sets a configuration setting by name. This name can either be a String or an Array

  • PDK.config.set(‘user.a.b.c’, …)

  • PDK.config.set([‘user’, ‘a’, ‘b’, ‘c’], …)

Parameters:

  • key (String, Array[String])

    The name of the configuration key to change

  • value (Object)

    The value to set the configuration setting to

  • options (Hash) (defaults to: {})

    Changes the behaviour of the setting process

Options Hash (options):

  • :force (Boolean)

    Disables any munging or array processing, and sets the value as it is. Default is false

Returns:

  • (Object)

    The new value of the configuration setting

Raises:

  • (ArgumentError)


180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/pdk/config.rb', line 180

def set(key, value, options = {})
  options = {
    force: false
  }.merge(options)

  names = key.is_a?(String) ? split_key_string(key) : key
  raise ArgumentError, 'Invalid configuration names' if names.nil? || !names.is_a?(Array) || names.empty?

  scope_name = names[0]
  raise ArgumentError, format("Unknown configuration root '%{name}'", name: scope_name) if all_scopes[scope_name].nil?

  deep_set_object(value, options[:force], send(all_scopes[scope_name]), *names[1..])
end