FEATURE: Allow plugins to easily add defaults to GlobalSetting

usage:

GlobalSetting.add_default("plugin_setting_name", "value")
This commit is contained in:
Sam 2017-11-16 08:38:24 +11:00
parent 0cdded8079
commit 20fbf81505
2 changed files with 22 additions and 0 deletions

View File

@ -137,6 +137,14 @@ class GlobalSetting
end
end
def self.add_default(name, default)
unless self.respond_to? name
define_singleton_method(name) do
default
end
end
end
class BaseProvider
def self.coerce(setting)
return setting == "true" if setting == "true" || setting == "false"

View File

@ -50,6 +50,20 @@ describe GlobalSetting do
end
end
describe '.add_default' do
after do
class <<GlobalSetting; remove_method :foo_bar_foo; end
end
it "can correctly add defaults" do
GlobalSetting.add_default "foo_bar_foo", 1
expect(GlobalSetting.foo_bar_foo).to eq(1)
GlobalSetting.add_default "cdn_url", "a"
expect(GlobalSetting.foo_bar_foo).not_to eq("a")
end
end
describe '.redis_config' do
describe 'when slave config is not present' do
it "should not set any connector" do