2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-22 23:35:06 -04:00
|
|
|
module SiteSettings; end
|
|
|
|
|
|
|
|
class SiteSettings::LocalProcessProvider
|
|
|
|
|
2014-03-28 01:36:17 -04:00
|
|
|
attr_accessor :current_site
|
|
|
|
|
2019-04-16 14:42:47 -04:00
|
|
|
class Setting
|
|
|
|
attr_accessor :name, :data_type, :value
|
|
|
|
|
|
|
|
def value_changed?
|
2019-04-17 07:00:21 -04:00
|
|
|
false
|
2019-04-16 14:42:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def saved_change_to_value?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name, data_type)
|
|
|
|
self.name = name
|
|
|
|
self.data_type = data_type
|
|
|
|
end
|
|
|
|
end
|
2013-06-22 23:35:06 -04:00
|
|
|
|
2014-03-28 01:36:17 -04:00
|
|
|
def settings
|
|
|
|
@settings[current_site] ||= {}
|
|
|
|
end
|
|
|
|
|
2017-08-06 21:43:09 -04:00
|
|
|
def initialize
|
2013-06-22 23:35:06 -04:00
|
|
|
@settings = {}
|
2014-03-28 01:36:17 -04:00
|
|
|
self.current_site = "test"
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2014-03-28 01:36:17 -04:00
|
|
|
settings.values
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def find(name)
|
2014-03-28 01:36:17 -04:00
|
|
|
settings[name]
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def save(name, value, data_type)
|
2015-09-09 09:34:53 -04:00
|
|
|
# NOTE: convert to string to simulate the conversion that is happening
|
|
|
|
# when using DbProvider
|
2019-04-16 14:42:47 -04:00
|
|
|
setting = settings[name]
|
|
|
|
if setting.blank?
|
|
|
|
setting = Setting.new(name, data_type)
|
|
|
|
settings[name] = setting
|
|
|
|
end
|
|
|
|
setting.value = value.to_s
|
|
|
|
DiscourseEvent.trigger(:site_setting_saved, setting)
|
|
|
|
setting
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(name)
|
2014-03-28 01:36:17 -04:00
|
|
|
settings.delete(name)
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
2014-03-28 01:36:17 -04:00
|
|
|
def clear
|
|
|
|
@settings[current_site] = {}
|
2013-06-22 23:35:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|