Class: SuperSettings::Configuration::Model
- Inherits:
-
Object
- Object
- SuperSettings::Configuration::Model
- Defined in:
- lib/super_settings/configuration.rb
Overview
Configuration for the models.
Instance Attribute Summary collapse
-
#after_save_blocks ⇒ Object
readonly
Returns the value of attribute after_save_blocks.
-
#cache ⇒ Object
Specify the cache implementation to use for caching the last updated timestamp for reloading changed records.
-
#changed_by_display ⇒ Object
readonly
Returns the value of attribute changed_by_display.
-
#storage ⇒ Object
Specify the storage engine to use for persisting settings.
Instance Method Summary collapse
-
#after_save {|setting| ... } ⇒ Object
Add an after_save callback to the setting model.
-
#define_changed_by_display {|changed_by| ... } ⇒ Object
Define how the changed_by attibute on the setting history will be displayed.
-
#initialize ⇒ Model
constructor
A new instance of Model.
- #storage_class ⇒ Class private
Constructor Details
#initialize ⇒ Model
Returns a new instance of Model.
144 145 146 147 148 149 |
# File 'lib/super_settings/configuration.rb', line 144 def initialize @storage = :active_record @after_save_blocks = [] @changed_by_display = nil @cache = nil end |
Instance Attribute Details
#after_save_blocks ⇒ Object (readonly)
Returns the value of attribute after_save_blocks.
142 143 144 |
# File 'lib/super_settings/configuration.rb', line 142 def after_save_blocks @after_save_blocks end |
#cache ⇒ Object
Specify the cache implementation to use for caching the last updated timestamp for reloading changed records. Defaults to Rails.cache
138 139 140 |
# File 'lib/super_settings/configuration.rb', line 138 def cache @cache end |
#changed_by_display ⇒ Object (readonly)
Returns the value of attribute changed_by_display.
142 143 144 |
# File 'lib/super_settings/configuration.rb', line 142 def changed_by_display @changed_by_display end |
#storage ⇒ Object
Specify the storage engine to use for persisting settings. The value can either be specified
as a full class name or an underscored class name for a storage classed defined in the
SuperSettings::Storage namespace. The default storage engine is SuperSettings::Storage::ActiveRecord.
154 155 156 |
# File 'lib/super_settings/configuration.rb', line 154 def storage @storage || :active_record end |
Instance Method Details
#after_save {|setting| ... } ⇒ Object
Add an after_save callback to the setting model. The block will be called with the setting object after it is saved.
177 178 179 |
# File 'lib/super_settings/configuration.rb', line 177 def after_save(&block) after_save_blocks << block end |
#define_changed_by_display {|changed_by| ... } ⇒ Object
Define how the changed_by attibute on the setting history will be displayed. The block will be called with the changed_by attribute and should return a string to display. The block will not be called if the changed_by attribute is nil.
190 191 192 |
# File 'lib/super_settings/configuration.rb', line 190 def define_changed_by_display(&block) @changed_by_display = block end |
#storage_class ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/super_settings/configuration.rb', line 160 def storage_class if storage.is_a?(Class) storage else class_name = storage.to_s.camelize if Storage.const_defined?("#{class_name}Storage") Storage.const_get("#{class_name}Storage") else class_name.constantize end end end |