2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-23 11:35:06 +08:00
|
|
|
module SiteSettings
|
|
|
|
end
|
|
|
|
|
|
|
|
class SiteSettings::LocalProcessProvider
|
2019-04-17 02:42:47 +08:00
|
|
|
class Setting
|
|
|
|
attr_accessor :name, :data_type, :value
|
|
|
|
|
|
|
|
def value_changed?
|
2019-04-17 19:00:21 +08:00
|
|
|
false
|
2019-04-17 02:42:47 +08: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-23 11:35:06 +08:00
|
|
|
|
2014-03-28 13:36:17 +08:00
|
|
|
def settings
|
|
|
|
@settings[current_site] ||= {}
|
|
|
|
end
|
|
|
|
|
2017-08-07 09:43:09 +08:00
|
|
|
def initialize
|
2013-06-23 11:35:06 +08:00
|
|
|
@settings = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def all
|
2014-03-28 13:36:17 +08:00
|
|
|
settings.values
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def find(name)
|
2014-03-28 13:36:17 +08:00
|
|
|
settings[name]
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def save(name, value, data_type)
|
2015-09-09 21:34:53 +08:00
|
|
|
# NOTE: convert to string to simulate the conversion that is happening
|
|
|
|
# when using DbProvider
|
2019-04-17 02:42:47 +08:00
|
|
|
setting = settings[name]
|
|
|
|
if setting.blank?
|
|
|
|
setting = Setting.new(name, data_type)
|
|
|
|
settings[name] = setting
|
|
|
|
end
|
|
|
|
setting.value = value.to_s
|
|
|
|
setting
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(name)
|
2014-03-28 13:36:17 +08:00
|
|
|
settings.delete(name)
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
2014-03-28 13:36:17 +08:00
|
|
|
def clear
|
|
|
|
@settings[current_site] = {}
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|
|
|
|
|
2020-08-18 21:38:30 +08:00
|
|
|
def current_site
|
|
|
|
RailsMultisite::ConnectionManagement.current_db
|
|
|
|
end
|
2013-06-23 11:35:06 +08:00
|
|
|
end
|