Class: SuperSettings::Configuration::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/super_settings/configuration.rb

Overview

Configuration for the models.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModel

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_blocksObject (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

#cacheObject

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_displayObject (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

#storageObject

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.

Yield Parameters:



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.

Examples:

define_changed_by_display { |changed_by| User.find_by(id: changed_by)&.name }

Yields:

  • Block of code to call on the controller at request time

Yield Parameters:

  • changed_by (String)

    The value of the changed_by attribute



168
169
170
# File 'lib/super_settings/configuration.rb', line 168

def define_changed_by_display(&block)
  @changed_by_display = block
end

#storage_classClass

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.

Returns:

  • (Class)


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