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/pagination.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/decimal_setting.rb,
app/models/system_settings/integer_setting.rb,
app/models/system_settings/type/string_list.rb,
app/models/system_settings/type/decimal_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/decimal_list_setting.rb,
app/models/system_settings/integer_list_setting.rb,
app/models/system_settings/errors/not_found_error.rb,
app/models/system_settings/errors/not_loaded_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_decimals_validator.rb,
app/models/system_settings/list_of_integers_validator.rb,
app/controllers/system_settings/application_controller.rb
Defined Under Namespace
Modules: Errors, Pagination, Type
Classes: ApplicationController, ApplicationRecord, BooleanSetting, Configurator, DecimalListSetting, DecimalSetting, Engine, IntegerListSetting, IntegerSetting, ListOfDecimalsValidator, ListOfIntegersValidator, ListOfStringsValidator, RootController, Setting, SettingsController, StringListSetting, StringSetting
Constant Summary
collapse
- VERSION =
"0.8.0"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.instrumenter ⇒ Object
Returns the value of attribute instrumenter.
7
8
9
|
# File 'lib/system_settings.rb', line 7
def instrumenter
@instrumenter
end
|
.settings_file_path ⇒ Object
Returns the value of attribute settings_file_path.
7
8
9
|
# File 'lib/system_settings.rb', line 7
def settings_file_path
@settings_file_path
end
|
Class Method Details
.[](name) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/system_settings.rb', line 10
def self.[](name)
instrument("system_settings.find", name: name) do |payload|
record = Setting.find_by(name: name)
unless record
message = <<~MESSAGE.strip
Couldn't find system setting #{name}
It might not be loaded from settings file(#{settings_file_path}).
To load missing settings with their initial values you can call SystemSettings.load from your Rails environment or run Rails task:
bin/rails system_settings:load RAILS_ENV=#{::Rails.env}
MESSAGE
raise(Errors::NotFoundError, message)
end
payload[:value] = record.value
end
end
|
.instrument(name, payload = {}, &block) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/system_settings.rb', line 44
def self.instrument(name, payload = {}, &block)
if instrumenter
instrumenter.instrument(name, payload, &block)
else
yield(payload)
end
end
|
.load(*names) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/system_settings.rb', line 28
def self.load(*names)
instrument("system_settings.load", path: settings_file_path) do |payload|
configurator = Configurator.from_file(settings_file_path)
payload[:success] = configurator.persist(only: names)
end
end
|
.reset_to_defaults ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/system_settings.rb', line 35
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
|