don't fail in foodsoft_config without database,

and use proper config defaults so that configuration editing has
sensible default values
This commit is contained in:
wvengen 2014-06-21 12:52:50 +02:00
parent 7b000c39eb
commit 90f60595e6
3 changed files with 13 additions and 6 deletions

View File

@ -60,10 +60,14 @@ class FoodsoftConfig
#
# FoodsoftConfig[:name] # => 'FC Test'
#
# To avoid errors when the database is not yet setup (when loading
# the initial database schema), cached settings are only being read
# when the settings table exists.
#
# @param key [String, Symbol]
# @return [Object] Value of the key.
def [](key)
if allowed_key?(key)
if RailsSettings::CachedSettings.table_exists? and allowed_key?(key)
value = RailsSettings::CachedSettings["foodcoop.#{self.scope}.#{key}"]
value = config[key] if value.nil?
value
@ -146,10 +150,13 @@ class FoodsoftConfig
end
# When new options are introduced, put backward-compatible defaults here, so that
# configuration files that haven't been updated, still work as they did.
# configuration files that haven't been updated, still work as they did. This also
# makes sure that the configuration editor picks up the defaults.
def set_missing
config.replace({
use_nick: true,
use_wiki: true,
use_messages: true,
use_apple_points: true,
# English is the default language, and this makes it show up as default.
default_locale: 'en',

View File

@ -4,8 +4,8 @@ require "deface"
module FoodsoftMessages
# Return whether messages are used or not.
# Enabled by default since it used to be part of the foodsoft core.
# Enabled by default in {FoodsoftConfig} since it used to be part of the foodsoft core.
def self.enabled?
FoodsoftConfig[:use_messages] != false
FoodsoftConfig[:use_messages]
end
end

View File

@ -6,8 +6,8 @@ require 'foodsoft_wiki/engine'
module FoodsoftWiki
# Return whether the wiki is used or not.
# Enabled by default since it used to be part of the foodsoft core.
# Enabled by default in {FoodsoftConfig} since it used to be part of the foodsoft core.
def self.enabled?
FoodsoftConfig[:use_wiki] != false
FoodsoftConfig[:use_wiki]
end
end