Module: ActiveAdmin::Settings::ClassMethods

Defined in:
lib/active_admin/helpers/settings.rb

Instance Method Summary collapse

Instance Method Details

#default_settingsObject


67
68
69
# File 'lib/active_admin/helpers/settings.rb', line 67

def default_settings
  @default_settings ||= {}
end

#deprecated_setting(name, default, message = nil) ⇒ Object


59
60
61
62
63
64
65
# File 'lib/active_admin/helpers/settings.rb', line 59

def deprecated_setting(name, default, message = nil)
  setting(name, default)

  message ||= "The #{name} setting is deprecated and will be removed."
  ActiveAdmin::Deprecation.deprecate self,     name,    message
  ActiveAdmin::Deprecation.deprecate self, :"#{name}=", message
end

#setting(name, default) ⇒ Object


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_admin/helpers/settings.rb', line 36

def setting(name, default)
  default_settings[name] = default
  attr_writer name

  # Create an accessor that looks up the default value if none is set.
  define_method name do
    if instance_variable_defined? "@#{name}"
      instance_variable_get "@#{name}"
    else
      read_default_setting name.to_sym
    end
  end

  define_method "#{name}?" do
    value = public_send(name)
    if value.is_a? Array
      value.any?
    else
      value.present?
    end
  end
end