Class: MotherBrain::ConfigManager
- Inherits:
-
Object
- Object
- MotherBrain::ConfigManager
- Includes:
- Celluloid, Celluloid::Notifications, Logging
- Defined in:
- lib/mb/config_manager.rb
Constant Summary collapse
- UPDATE_MSG =
'config_manager.configure'.freeze
Instance Attribute Summary collapse
- #config ⇒ MB::Config readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(new_config) ⇒ ConfigManager
constructor
A new instance of ConfigManager.
-
#reload ⇒ Object
Reload the current configuration from disk.
-
#reloading? ⇒ Boolean
Check if the config manager is already attempting to reload it’s configuration.
-
#update(new_config) ⇒ Object
Update the current configuration.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
#initialize(new_config) ⇒ ConfigManager
Returns a new instance of ConfigManager.
24 25 26 27 28 29 |
# File 'lib/mb/config_manager.rb', line 24 def initialize(new_config) log.debug { "Config Manager starting..." } @reload_mutex = Mutex.new @reloading = false set_config(new_config) end |
Instance Attribute Details
#config ⇒ MB::Config (readonly)
19 20 21 |
# File 'lib/mb/config_manager.rb', line 19 def config @config end |
Class Method Details
.instance ⇒ Celluloid::Actor(ConfigManager)
7 8 9 |
# File 'lib/mb/config_manager.rb', line 7 def instance MB::Application[:config_manager] or raise Celluloid::DeadActorError, "config manager not running" end |
Instance Method Details
#reload ⇒ Object
Reload the current configuration from disk
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mb/config_manager.rb', line 42 def reload reload_mutex.synchronize do unless reloading? @reloading = true update(config.reload) end end @reloading = false end |
#reloading? ⇒ Boolean
Check if the config manager is already attempting to reload it’s configuration
56 57 58 |
# File 'lib/mb/config_manager.rb', line 56 def reloading? @reloading end |
#update(new_config) ⇒ Object
Update the current configuration
34 35 36 37 38 39 |
# File 'lib/mb/config_manager.rb', line 34 def update(new_config) set_config(new_config) MB.log.info "[ConfigManager] Configuration has changed: notifying subscribers..." publish(UPDATE_MSG, self.config) end |