Module: ActiveadminSettings::SettingMethods

Included in:
Setting
Defined in:
app/models/activeadmin_settings/setting.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/models/activeadmin_settings/setting.rb', line 3

def self.included(base)
  base.mount_uploader  :file, ActiveadminSettings::SettingsFileUploader

  # Validators
  base.validates_presence_of   :name
  base.validates_uniqueness_of :name
  base.validates_length_of     :name, minimum: 1

  base.extend ClassMethods
end

Instance Method Details

#default_valueObject



37
38
39
40
41
42
43
44
45
# File 'app/models/activeadmin_settings/setting.rb', line 37

def default_value
  val = (ActiveadminSettings.all_settings[name]["default_value"] ||= "").to_s

  if type == "file" and not val.include? '//'
    val = ActionController::Base.helpers.asset_path(val)
  end

  val
end

#descriptionObject



33
34
35
# File 'app/models/activeadmin_settings/setting.rb', line 33

def description
  (ActiveadminSettings.all_settings[name]["description"] ||= "").to_s
end

#typeObject

Instance



29
30
31
# File 'app/models/activeadmin_settings/setting.rb', line 29

def type
  (ActiveadminSettings.all_settings[name]["type"] ||= "string").to_s
end

#valueObject



47
48
49
50
51
# File 'app/models/activeadmin_settings/setting.rb', line 47

def value
  val = respond_to?(type) ? send(type).to_s : send(:string).to_s
  val = default_value if val.empty?
  val.html_safe
end