1 # Handles storing of preferences for the application.
3 # This is an internal structure mostly, which is useful to access / save
6 # Prefs are used all over to handle decisions that we'd rather
7 # not use config files for.
11 include DataMapper::Persistable
13 # Types can hold strings, booleans, or pointers to
14 # other records (like country)
15 CC_PROCESSORS = ['Authorize.net', 'PayPal IPN']
16 MAIL_AUTH = ['none', 'plain', 'login', 'cram_md5']
18 property :name, :string, :default => "", :nullable => false
19 property :value, :string, :default => ""
21 #validates_presence_of :name, :type
22 #validates_uniqueness_of :name
25 def self.find_by_name(name)
29 # Can throw an error if these items aren't set.
30 # Make sure to wrap any block that calls this
31 def self.init_mail_settings
32 # SET MAIL SERVER SETTINGS FROM PREFERENCES
33 mail_host = find_by_name('mail_host').value
34 mail_server_settings = {
35 :address => mail_host,
37 :port => find_by_name('mail_port').value,
39 mail_auth_type = find_by_name('mail_auth_type').value
40 if !mail_auth_type != 'none'
41 mail_server_settings[:authentication] = mail_auth_type.to_sym
42 mail_server_settings[:user_name] = find_by_name('mail_username').value
43 mail_server_settings[:password] = find_by_name('mail_password').value
45 ActionMailer::Base.smtp_settings = mail_server_settings
48 # Saves preferences passed in from our form.
50 def self.save_settings(settings)
51 logger.info "SERVER SETTINGS..."
52 logger.info settings.inspect
53 settings.each do |name, value|
54 update_all("value = '#{value}'", "name = '#{name}'")
58 # Determines if a preference is "true" or not.
59 # This is the ghetto, bootleg way to determine booleans.
61 if self.value == '1' || self.value == 'true'