Class: Knockoff::Config
- Inherits:
-
Object
- Object
- Knockoff::Config
- Defined in:
- lib/knockoff/config.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
The current environment.
-
#replica_configs ⇒ Object
readonly
An array of configs to use for the replica pool.
-
#replicas_configurations ⇒ Object
readonly
A hash of replica configs to their config hash.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#properly_configured? ⇒ Boolean
If replica_configs actually containts some configuration information, then we know it was properly configured.
- #replica_database_keys ⇒ Object
- #replica_env_keys ⇒ Object
- #update_replica_configs(new_configs) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/knockoff/config.rb', line 13 def initialize @environment = 'development' @replicas_configurations = {} set_replica_configs if !properly_configured? && Knockoff.enabled puts "[Knockoff] WARNING: Detected enabled Knockoff without proper replica pool configuration. Setting Knockoff.enabled to false." Knockoff.enabled = false end end |
Instance Attribute Details
#environment ⇒ Object (readonly)
The current environment. Normally set to Rails.env, but will default to ‘development’ outside of Rails apps.
5 6 7 |
# File 'lib/knockoff/config.rb', line 5 def environment @environment end |
#replica_configs ⇒ Object (readonly)
An array of configs to use for the replica pool.
8 9 10 |
# File 'lib/knockoff/config.rb', line 8 def replica_configs @replica_configs end |
#replicas_configurations ⇒ Object (readonly)
A hash of replica configs to their config hash.
11 12 13 |
# File 'lib/knockoff/config.rb', line 11 def replicas_configurations @replicas_configurations end |
Instance Method Details
#properly_configured? ⇒ Boolean
If replica_configs actually containts some configuration information, then we know it was properly configured. Improper URI’s will be ignored during the initialization step.
46 47 48 |
# File 'lib/knockoff/config.rb', line 46 def properly_configured? !@replica_configs.empty? end |
#replica_database_keys ⇒ Object
24 25 26 |
# File 'lib/knockoff/config.rb', line 24 def replica_database_keys @replicas_configurations.keys end |
#replica_env_keys ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/knockoff/config.rb', line 28 def replica_env_keys if ENV['KNOCKOFF_REPLICA_ENVS'].nil? [] else ENV['KNOCKOFF_REPLICA_ENVS'].split(',').map(&:strip) end end |
#update_replica_configs(new_configs) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/knockoff/config.rb', line 36 def update_replica_configs(new_configs) ActiveRecord::Base.configurations['knockoff_replicas'].merge(new_configs) if ActiveRecord::Base.configurations['knockoff_replicas'].present? @replicas_configurations.each do |key, _config| update_replica_config(key, new_configs) end end |