Work for short time with :state_current and :state support.

This commit is contained in:
Martin Edenhofer 2015-09-25 17:15:41 +02:00
parent ad1b9b18bf
commit 52718a41c0

View file

@ -31,7 +31,11 @@ set config setting
if !setting
fail "Can't find config setting '#{name}'"
end
setting.state_current = { value: value }
if setting.respond_to?(:state_current)
setting.state_current = { value: value }
else
setting.state = { value: value }
end
setting.save
logger.info "Setting.set(#{name}, #{value.inspect})"
end
@ -66,9 +70,15 @@ reset config setting to default
if !setting
fail "Can't find config setting '#{name}'"
end
setting.state_current = setting.state_initial
setting.save
logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})"
if setting.respond_to?(:state_current)
setting.state_current = setting.state_initial
setting.save
logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})"
else
setting.state = setting.state_initial
setting.save
logger.info "Setting.reset(#{name}, #{setting.state_current.inspect})"
end
load
@@current[:settings_config][name]
end
@ -85,9 +95,16 @@ reset config setting to default
# read all config settings
config = {}
Setting.select('name, state_current').order(:id).each { |setting|
config[setting.name] = setting.state_current[:value]
}
s = Setting.new
if s.respond_to?(:state_current)
Setting.select('name, state_current').order(:id).each { |setting|
config[setting.name] = setting.state_current[:value]
}
else
Setting.select('name, state').order(:id).each { |setting|
config[setting.name] = setting.state[:value]
}
end
# config lookups
config.each { |key, value|
@ -105,7 +122,11 @@ reset config setting to default
# set initial value in state_initial
def set_initial
self.state_initial = state_current
if self.respond_to?(:state_current)
self.state_initial = state_current
else
self.state_initial = state
end
end
# set new cache
@ -144,6 +165,10 @@ reset config setting to default
# convert state ot hash to be able to store it as store
def state_check
return if state && state.respond_to?('has_key?') && state.key?(:value)
self.state_current = { value: state }
if self.respond_to?(:state_current)
self.state_current = { value: state }
else
self.state = { value: state }
end
end
end