Class: MotherBrain::ConfigManager

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



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

#configMB::Config (readonly)

Returns:



19
20
21
# File 'lib/mb/config_manager.rb', line 19

def config
  @config
end

Class Method Details

.instanceCelluloid::Actor(ConfigManager)

Returns:

Raises:

  • (Celluloid::DeadActorError)

    if ConfigManager has not been started



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

#reloadObject

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

Returns:

  • (Boolean)


56
57
58
# File 'lib/mb/config_manager.rb', line 56

def reloading?
  @reloading
end

#update(new_config) ⇒ Object

Update the current configuration

Parameters:



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