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.
122 123 124 125 126 127 |
# File 'lib/super_settings/configuration.rb', line 122 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.
120 121 122 |
# File 'lib/super_settings/configuration.rb', line 120 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
116 117 118 |
# File 'lib/super_settings/configuration.rb', line 116 def cache @cache end |
#changed_by_display ⇒ Object (readonly)
Returns the value of attribute changed_by_display.
120 121 122 |
# File 'lib/super_settings/configuration.rb', line 120 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.
132 133 134 |
# File 'lib/super_settings/configuration.rb', line 132 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.
155 156 157 |
# File 'lib/super_settings/configuration.rb', line 155 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.
168 169 170 |
# File 'lib/super_settings/configuration.rb', line 168 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.
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/super_settings/configuration.rb', line 138 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 |