Module: ConstConf

Extended by:
ActiveSupport::Concern
Includes:
Errors
Defined in:
lib/const_conf.rb,
lib/const_conf.rb,
lib/const_conf/tree.rb,
lib/const_conf/version.rb

Overview

A configuration management module that provides environment variable-based settings with validation and thread-safe operations.

ConstConf enables defining configuration settings through environment variables, including support for default values, required validation, decoding logic, and descriptive metadata. It offers thread-safe registration and retrieval of configuration values while providing integration with Rails application initialization cycles.

Defined Under Namespace

Modules: ConstConfHelper, DirPlugin, EnvDirExtension, Errors, FilePlugin, JSONPlugin, SettingAccessor, YAMLPlugin Classes: Railtie, Setting, Tree

Constant Summary collapse

VERSION =

ConstConf version

'0.2.2'
VERSION_ARRAY =

:nodoc:

VERSION.split('.').map(&:to_i)
VERSION_MAJOR =

:nodoc:

VERSION_ARRAY[0]
VERSION_MINOR =

:nodoc:

VERSION_ARRAY[1]
VERSION_BUILD =

:nodoc:

VERSION_ARRAY[2]

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.module_filesHash?

The module_files accessor provides read and write access to the module_files instance variable.

This method serves as a getter and setter for the module_files attribute, which stores a hash mapping modules to their corresponding file paths.

variable

Returns:

  • (Hash, nil)

    the current value of the module_files instance



49
50
51
# File 'lib/const_conf.rb', line 49

def module_files
  @module_files
end

Class Method Details

.destroyArray<String>

Destroys all registered configuration modules and returns their file paths.

This method synchronizes access to the global configuration registry and removes all registered modules from their respective parent namespaces. It collects the file paths associated with each module before removing them, returning an array of the collected file paths.

destroyed modules

Returns:

  • (Array<String>)

    an array containing the file paths of the



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/const_conf.rb', line 75

def destroy
  monitor.synchronize do
    files = []
    while pair = ConstConf.module_files.shift
      modul, file = pair
      if modul.module_parent.const_defined?(modul.name)
        modul.module_parent.send(:remove_const, modul.name)
      end
      files << file
    end
    files
  end
end

.monitorMonitor

Returns the monitor instance for thread synchronization.

This method provides a singleton Monitor instance that can be used to synchronize access to shared resources across threads. It ensures that only one thread can execute critical sections of code at a time.

synchronization

Returns:

  • (Monitor)

    the singleton Monitor instance used for thread



37
38
39
# File 'lib/const_conf.rb', line 37

def monitor
  @monitor ||= Monitor.new
end

.register(configuration, file) ⇒ Object

Registers a module-file mapping in the global registry.

This method associates a module with its corresponding file path in the global module_files hash. The registration is performed in a thread-safe manner using the monitor for synchronization.

Parameters:

  • configuration (Module)

    the module to register

  • file (String)

    the file path associated with the module



59
60
61
62
63
# File 'lib/const_conf.rb', line 59

def register(configuration, file)
  monitor.synchronize do
    module_files[configuration] ||= file
  end
end

.reloadObject

Reloads all registered configuration modules by destroying them and re-loading their associated files.

This method ensures that all configuration modules currently registered with ConstConf are destroyed and then reloaded from their respective files. It performs this operation in a thread-safe manner using the monitor for synchronization.



96
97
98
99
# File 'lib/const_conf.rb', line 96

def reload
  monitor.synchronize { destroy.each { load it } }
  nil
end