Module: SystemSettings
- Defined in:
- lib/system_settings.rb,
lib/system_settings/engine.rb,
lib/system_settings/version.rb,
app/models/system_settings/setting.rb,
app/models/system_settings/configurator.rb,
app/models/system_settings/errors/error.rb,
app/models/system_settings/string_setting.rb,
app/models/system_settings/boolean_setting.rb,
app/models/system_settings/integer_setting.rb,
app/models/system_settings/type/string_list.rb,
app/models/system_settings/type/integer_list.rb,
app/models/system_settings/application_record.rb,
app/models/system_settings/string_list_setting.rb,
app/controllers/system_settings/root_controller.rb,
app/models/system_settings/integer_list_setting.rb,
app/models/system_settings/errors/not_found_error.rb,
app/controllers/system_settings/settings_controller.rb,
app/models/system_settings/list_of_strings_validator.rb,
app/models/system_settings/errors/settings_read_error.rb,
app/models/system_settings/list_of_integers_validator.rb,
app/controllers/system_settings/application_controller.rb
Defined Under Namespace
Modules: Errors, Type
Classes: ApplicationController, ApplicationRecord, BooleanSetting, Configurator, Engine, IntegerListSetting, IntegerSetting, ListOfIntegersValidator, ListOfStringsValidator, RootController, Setting, SettingsController, StringListSetting, StringSetting
Constant Summary
collapse
- VERSION =
"0.5.1".freeze
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.instrumenter ⇒ Object
Returns the value of attribute instrumenter.
5
6
7
|
# File 'lib/system_settings.rb', line 5
def instrumenter
@instrumenter
end
|
.settings_file_path ⇒ Object
Returns the value of attribute settings_file_path.
5
6
7
|
# File 'lib/system_settings.rb', line 5
def settings_file_path
@settings_file_path
end
|
Class Method Details
.[](name) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/system_settings.rb', line 8
def self.[](name)
instrument("system_settings.find", name: name) do |payload|
record = Setting.find_by(name: name)
unless record
message = "Couldn't find system setting #{name}\n\n"
message << "It might not be loaded from settings file(#{settings_file_path}).\n"
message << "To load missing settings with their initial values you "
message << "can call SystemSettings.load from your Rails environment or run Rails task:\n\n"
message << " bin/rails system_settings:load RAILS_ENV=#{::Rails.env}"
raise(Errors::NotFoundError, message)
end
payload[:value] = record.value
end
end
|
.instrument(name, payload = {}, &block) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/system_settings.rb', line 39
def self.instrument(name, payload = {}, &block)
if instrumenter
instrumenter.instrument(name, payload, &block)
else
yield(payload)
end
end
|
.load ⇒ Object
23
24
25
26
27
28
|
# File 'lib/system_settings.rb', line 23
def self.load
instrument("system_settings.load", path: settings_file_path) do |payload|
configurator = Configurator.from_file(settings_file_path)
payload[:success] = configurator.persist
end
end
|
.reset_to_defaults ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/system_settings.rb', line 30
def self.reset_to_defaults
instrument("system_settings.reset_to_defaults", path: settings_file_path) do |payload|
configurator = Configurator.from_file(settings_file_path)
Setting.transaction do
payload[:success] = configurator.purge && configurator.persist
end
end
end
|