lib/super_settings/configuration.rb in super_settings-1.0.0 vs lib/super_settings/configuration.rb in super_settings-1.0.1
- old
+ new
@@ -20,12 +20,18 @@
# on them. If this is not defined, the superclass will be SuperSettings::ApplicationController.
# It can be set to either a class or a class name. Setting to a class name is preferrable
# since it will be compatible with class reloading in a development environment.
attr_writer :superclass
+ def initialize
+ @superclass = nil
+ @web_ui_enabled = true
+ @changed_by_block = nil
+ end
+
def superclass
- if defined?(@superclass) && @superclass.is_a?(String)
+ if @superclass.is_a?(String)
@superclass.constantize
else
@superclass
end
end
@@ -52,13 +58,10 @@
# Enable or disable the web UI (the REST API will always be enabled).
attr_writer :web_ui_enabled
def web_ui_enabled?
- unless defined?(@web_ui_enabled)
- @web_ui_enabled = true
- end
!!@web_ui_enabled
end
# Enhance the controller. You can define methods or call controller class methods like
# +before_action+, etc. in the block. These will be applied to the engine controller.
@@ -85,11 +88,11 @@
# Return the value of +define_changed_by+ block.
#
# @api private
def changed_by(controller)
- if defined?(@changed_by_block) && @changed_by_block
+ if @changed_by_block
controller.instance_eval(&@changed_by_block)
end
end
end
@@ -99,19 +102,23 @@
# changed records. Defaults to Rails.cache
attr_accessor :cache
attr_writer :storage
+ attr_reader :after_save_blocks, :changed_by_display
+
+ def initialize
+ @storage = :active_record
+ @after_save_blocks = []
+ @changed_by_display = nil
+ end
+
# 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+.
def storage
- if defined?(@storage) && @storage
- @storage
- else
- :active_record
- end
+ @storage || :active_record
end
# @return [Class]
# @api private
def storage_class
@@ -133,16 +140,10 @@
# @yieldparam setting [SuperSettings::Setting]
def after_save(&block)
after_save_blocks << block
end
- # @return [Array<Proc>] The after_save block
- # @api private
- def after_save_blocks
- @after_save_blocks ||= []
- end
-
# 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.
#
# @example
@@ -150,15 +151,9 @@
#
# @yield Block of code to call on the controller at request time
# @yieldparam changed_by [String] The value of the changed_by attribute
def define_changed_by_display(&block)
@changed_by_display = block
- end
-
- # @return [Proc, nil] The block to call to display the changed_by attribute in setting history
- # @api private
- def changed_by_display
- @changed_by_display if defined?(@changed_by_display)
end
end
# Return the model specific configuration object.
attr_reader :model