2012-04-10 14:06:46 +00:00
|
|
|
class Setting < ActiveRecord::Base
|
2012-04-13 13:51:10 +00:00
|
|
|
store :options
|
|
|
|
store :state
|
|
|
|
store :state_initial
|
2012-04-10 14:06:46 +00:00
|
|
|
before_create :set_initial
|
|
|
|
|
|
|
|
@@config = nil
|
|
|
|
|
|
|
|
def self.load
|
2012-04-13 13:51:10 +00:00
|
|
|
|
|
|
|
# check if config is already generated
|
2012-04-10 14:06:46 +00:00
|
|
|
return @@config if @@config
|
2012-04-13 13:51:10 +00:00
|
|
|
|
|
|
|
# read all config settings
|
2012-04-10 14:06:46 +00:00
|
|
|
config = {}
|
|
|
|
Setting.select('name, state').order(:id).each { |setting|
|
|
|
|
config[setting.name] = setting.state[:value]
|
|
|
|
}
|
2012-04-13 13:51:10 +00:00
|
|
|
|
|
|
|
# config lookups
|
|
|
|
config.each { |key, value|
|
|
|
|
next if value.class.to_s != 'String'
|
|
|
|
config[key].gsub!( /\#\{config\.(.+?)\}/ ) { |s|
|
|
|
|
s = config[$1].to_s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# store for class requests
|
2012-04-10 14:06:46 +00:00
|
|
|
@@config = config
|
|
|
|
return config
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get(name)
|
|
|
|
self.load
|
|
|
|
return @@config[name]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def set_initial
|
|
|
|
self.state_initial = self.state
|
|
|
|
end
|
|
|
|
end
|