Sha256: a04d8857298b88c02ef7365f04a467f6bf83cc83aba551174d01a8721b2017b7

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# The sys_config table stores the system configuration for a Sugoi-Mail
# This includes things like the mail server and the default mailing list
# class for new users.
#
# sys_config has the following data members, although you probably won't
# need to know them due to the fact that you access configuration parameters
# directly rather than by searching for them:
# +name+::        The name of the configuration parameter.
# +value+::       The value of the configuration parameter.  This is
#                 serialized as YAML for the moment, until the YAML
#                 storage format starts presenting problems.
#
# To use this library, simply refer to SysConfig.parameter_name.  For example,
# if the SMTP host were stored in the parameter "smtphost", you'd retrieve
# it with a simple
#
#     SysConfig.smtphost
#
# and you'd set it with:
#
#     SysConfig.smtphost = "localhost"

class SysConfig < ActiveRecord::Base
    serialize :value

    def self.method_missing meth, *args
        begin
            super(meth, *args)
        rescue NoMethodError
            config_param = meth.to_s
            if config_param =~ /\=$/ then
                if args.length > 1 then
                    raise ArgumentError, "How did you manage that?"
                end
                config_param.sub! /\=$/,''
                conf = self.find_or_create_by_name config_param
                conf.value = args[0]
                if conf.save
                    return conf
                end
            else
                conf = self.find_by_name config_param
                unless conf
                    raise ActiveRecord::RecordNotFound, 
                        "config param #{config_param} does not exist"
                end
                conf.value
            end
        end
    end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sugoi-mail-0.0.5 app/models/sys_config.rb
sugoi-mail-0.0.3 app/models/sys_config.rb
sugoi-mail-0.0.2 app/models/sys_config.rb
sugoi-mail-0.1.5 app/models/sys_config.rb
sugoi-mail-0.1.0 app/models/sys_config.rb
sugoi-mail-0.3.0 app/models/sys_config.rb
sugoi-mail-0.3.2 app/models/sys_config.rb