Class: SystemConfiguration

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/models/system_configuration.rb

Overview

The System configuration. Various configuration items that can be updated/defined at run time instead of AppConfiguration that is defining things statically in code.

In hindsight (being 20/20) this should have been named stack_configuration as now the stack UI is what allows the administrator to update/configure this information.

Use of this class allows you to simply ask for the configuration parameter directly without first having to get an instance of it.

SystemConfiguration.queue_impl #=> ‘RedisQueue’

This method only is allowed for accessors, you should NEVER set values on the SystemConfiguration unless you are updating via the Admin or Stack UI, or during testing to setup a specific configuration for that.

Class Method Summary collapse

Class Method Details

.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

.method_missing(method, *_args) ⇒ Object



75
76
77
# File 'lib/models/system_configuration.rb', line 75

def method_missing(method, *_args)
  configuration.send method
end

.respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/models/system_configuration.rb', line 79

def respond_to_missing?(method_name, _include_private = false)
  SystemConfiguration.fields.include?(method_name.to_sym)
end