Method: SuperSettings::RestAPI.update

Defined in:
lib/super_settings/rest_api.rb

.update(settings_params, changed_by = nil) ⇒ Hash

The update operation uses a transaction to atomically update all settings.

Examples:

POST /settings

The format of the parameters is an array of hashes with each setting identified by the key.
The settings should include either "value" and "value_type" (and optionally "description") to
insert or update a setting, or "deleted" to delete the setting.

{ settings: [
    {
      key: string,
      value: object,
      value_type: string,
      description: string,
    },
    {
      key: string,
      deleted: boolean,
    },
    ...
  ]
}

The response will be either

{success: true}

or

{success: false, errors: {key => [string], ...}}

Parameters:

  • settings_params (Array)

    array of setting parameter hashes

  • changed_by (String) (defaults to: nil)

    identifier for who made the changes

Returns:

  • (Hash)

    result hash with success status and any errors



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/super_settings/rest_api.rb', line 93

def update(settings_params, changed_by = nil)
  all_valid, settings = Setting.bulk_update(Array(settings_params), changed_by)
  if all_valid
    {success: true}
  else
    errors = {}
    settings.each do |setting|
      if setting.errors.any?
        errors[setting.key] = setting.errors.values.flatten
      end
    end
    {success: false, errors: errors}
  end
end