Sha256: 140d28ba2f9db5dd7cb52b12adabf9fc588ec10f5bfbbf334d5ae5b14a9ebc2b
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
module SugarCRM @@connection = nil def self.connection @@connection end def self.connection=(connection) @@connection = connection end def self.connect(url=SugarCRM::Environment.config[:base_url], user=SugarCRM::Environment.config[:username], pass=SugarCRM::Environment.config[:password], options={}) SugarCRM::Base.establish_connection(url, user, pass, options) end class << self alias :connect! :connect end @@modules = [] def self.modules @@modules end def self.modules=(modules) @@modules = modules end def self.current_user SugarCRM::User.find_by_user_name(connection.user) end # If a user tries to access a SugarCRM class before they're logged in, # try to log in using credentials from config file. # This will trigger module loading, # and we can then attempt to return the requested class automagically def self.const_missing(sym) # if we're logged in, modules should be loaded and available if SugarCRM.connection && SugarCRM.connection.logged_in? super else # here, we initialize the environment (which happens on any method call, if singleton hasn't already been initialized) # initializing the environment will log user in if credentials present in config file # if it isn't possible to log in and access modules, pass the exception on super unless SugarCRM::Environment.connection_info_loaded? # try and return the requested module SugarCRM.const_get(sym) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sugarcrm-0.9.10 | lib/sugarcrm/module_methods.rb |
sugarcrm-0.9.9 | lib/sugarcrm/module_methods.rb |