Method: SystemConfiguration.configuration

Defined in:
lib/models/system_configuration.rb

.configurationObject

Fetch the system configuration based on environment name. First try the rails cache if not there, then go to the database.

Also, if an argument error is thrown, then just fetch from the database.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/models/system_configuration.rb', line 56

def configuration
  cache_key = "SystemConfiguration::#{ENV['RACK_ENV']}"

  begin
    config = App47Cache.get(cache_key) || SystemConfiguration.where(environment: ENV['RACK_ENV']).first
  rescue ArgumentError
    # This seems to happen in testing relative to Country, when it does, remove
    # ourselves from the cache and return the DB entry.
    App47Cache.delete cache_key
    config = SystemConfiguration.where(environment: ENV['RACK_ENV']).first
  end
  if config.nil?
    SystemConfiguration.create
  else
    App47Cache.set(cache_key, config, 300)
    config
  end
end