Module: SuperSettings::ControllerActions

Defined in:
lib/super_settings/controller_actions.rb

Overview

Module used to build the SuperSettings::SettingsController for Rails applications. This controller is defined at runtime since it is assumed that the superclass will be one of the application’s own base controller classes since the application will want to define authentication and authorization criteria.

The controller is built by extending the class defined by the Configuration object and then mixing in this module.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



14
15
16
17
18
# File 'lib/super_settings/controller_actions.rb', line 14

def self.included(base)
  base.layout "super_settings/settings"
  base.helper SettingsHelper
  base.protect_from_forgery with: :exception, if: :protect_from_forgery?
end

Instance Method Details

#historyObject

API endpoint for getting the history of a setting. See SuperSettings::RestAPI for details.



53
54
55
56
57
58
59
60
# File 'lib/super_settings/controller_actions.rb', line 53

def history
  setting_history = SuperSettings::RestAPI.history(params[:key], offset: params[:offset], limit: params[:limit])
  if setting_history
    render json: setting_history
  else
    render json: nil, status: 404
  end
end

#indexObject

API endpoint for getting active settings. See SuperSettings::RestAPI for details.



27
28
29
# File 'lib/super_settings/controller_actions.rb', line 27

def index
  render json: SuperSettings::RestAPI.index
end

#last_updated_atObject

API endpoint for getting the last time a setting was changed. See SuperSettings::RestAPI for details.



63
64
65
# File 'lib/super_settings/controller_actions.rb', line 63

def last_updated_at
  render json: SuperSettings::RestAPI.last_updated_at
end

#rootObject

Render the HTML application for managing settings.



21
22
23
24
# File 'lib/super_settings/controller_actions.rb', line 21

def root
  html = SuperSettings::Application.new.render
  render html: html.html_safe, layout: true
end

#showObject

API endpoint for getting a setting. See SuperSettings::RestAPI for details.



32
33
34
35
36
37
38
39
# File 'lib/super_settings/controller_actions.rb', line 32

def show
  setting = SuperSettings::RestAPI.show(params[:key])
  if setting
    render json: setting
  else
    render json: nil, status: 404
  end
end

#updateObject

API endpoint for updating settings. See SuperSettings::RestAPI for details.



42
43
44
45
46
47
48
49
50
# File 'lib/super_settings/controller_actions.rb', line 42

def update
  changed_by = SuperSettings.configuration.controller.changed_by(self)
  result = SuperSettings::RestAPI.update(params[:settings], changed_by)
  if result[:success]
    render json: result
  else
    render json: result, status: 422
  end
end

#updated_sinceObject

API endpoint for getting settings that have changed since specified time. See SuperSettings::RestAPI for details.



68
69
70
# File 'lib/super_settings/controller_actions.rb', line 68

def updated_since
  render json: SuperSettings::RestAPI.updated_since(params[:time])
end