Class: RunTimeSettings::Settings
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RunTimeSettings::Settings
- Defined in:
- lib/run_time_settings/settings.rb
Overview
Settings
Model settings holds namespaced key-value pairs. This acts as the data store for the PersistentAttributes mixin. See RunTimeSettings::PersistentAttributes.settings for information.
Class Method Summary collapse
- .add_setting_type(namespace, key, type) ⇒ Object
- .read(namespace, key) ⇒ Object
- .write(namespace, key, value) ⇒ Object
Class Method Details
.add_setting_type(namespace, key, type) ⇒ Object
14 15 16 |
# File 'lib/run_time_settings/settings.rb', line 14 def add_setting_type(namespace, key, type) setting_types[[namespace, key]] = type end |
.read(namespace, key) ⇒ Object
18 19 20 21 |
# File 'lib/run_time_settings/settings.rb', line 18 def read(namespace, key) value = RunTimeSettings::Settings.find_by(namespace:, key_name: key)&.db_value type_for(namespace, key).deserialize(value) if value.present? end |
.write(namespace, key, value) ⇒ Object
23 24 25 26 |
# File 'lib/run_time_settings/settings.rb', line 23 def write(namespace, key, value) setting = RunTimeSettings::Settings.find_or_initialize_by(namespace:, key_name: key) setting.update!(db_value: type_for(namespace, key).serialize(value)) end |