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.5.0'- 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
-
.module_files ⇒ Hash?
The module_files accessor provides read and write access to the module_files instance variable.
Class Method Summary collapse
-
.destroy ⇒ Array<String>
Destroys all registered configuration modules and returns their file paths.
-
.monitor ⇒ Monitor
Returns the monitor instance for thread synchronization.
-
.register(configuration, file) ⇒ Object
Registers a module-file mapping in the global registry.
-
.reload ⇒ Object
Reloads all registered configuration modules by destroying them and re-loading their associated files.
Class Attribute Details
.module_files ⇒ Hash?
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
51 52 53 |
# File 'lib/const_conf.rb', line 51 def module_files @module_files end |
Class Method Details
.destroy ⇒ Array<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
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/const_conf.rb', line 77 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 |
.monitor ⇒ Monitor
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
39 40 41 |
# File 'lib/const_conf.rb', line 39 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.
61 62 63 64 65 |
# File 'lib/const_conf.rb', line 61 def register(configuration, file) monitor.synchronize do module_files[configuration] ||= file end end |
.reload ⇒ Object
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.
98 99 100 101 |
# File 'lib/const_conf.rb', line 98 def reload monitor.synchronize { destroy.each { load _1 } } nil end |