added datetime setting format

pull/6341/head
Markus Kahl 7 years ago
parent b549e723e2
commit ddf0419843
  1. 24
      app/models/setting.rb

@ -247,14 +247,26 @@ class Setting < ActiveRecord::Base
def self.deserialize(name, v)
default = @@available_settings[name]
v = YAML::load(v) if default['serialized'] && v.is_a?(String)
unless v.blank?
v = v.to_sym if default['format'] == 'symbol'
v = v.to_i if default['format'] == 'int'
if default['serialized'] && v.is_a?(String)
YAML::load(v)
elsif v.present?
read_formatted_setting v, default["format"]
else
v
end
end
v
def self.read_formatted_setting(value, format)
case format
when "symbol"
value.to_sym
when "int"
value.to_i
when "datetime"
DateTime.parse value
else
value
end
end
require_dependency 'setting/callbacks'

Loading…
Cancel
Save