class Nucleon::Config::Collection
Configuration collection¶ ↑
The Nucleon::Config::Collection
class defines a container for logging properties and values. This class is not currently used within Nucleon
itself but it does serve as a configuration log for the corl gem.
This basically provides standard access methods. It implements the ability to dump registered properties to the file system through a machine readable format.
How we use it in CORL:
-
As we look up configurations and modify them we save new values in global registry
-
When we get to the end of our execution we log them to disk so they are viewable
Right now, largely for historical reasons, this class is structured as a global interface and collection for grouping all of the defined options. It was originally contained within Nucleon::Config
as part of the global configuration interface. In the future, this class will be refactored to support multiple property logs and will have more fully refined persistence methods.
TODO: Mutex synchronization probably not needed?
For usage:
-
See core configuration object
Nucleon::Config
-
See configuration mixin
Nucleon::Mixin::ConfigCollection
Public Class Methods
Clear all properties from the collection.
-
Parameters
-
Returns
- Void
-
This method does not currently have a return value
-
Errors
# File lib/core/config/collection.rb 125 def self.clear 126 @@lock.synchronize do 127 @@properties = {} 128 end 129 end
Delete property from collection.
-
Parameters
- String, Symbol
-
name Property name to remove
-
Returns
- Void
-
This method does not currently have a return value
-
Errors
# File lib/core/config/collection.rb 110 def self.delete(name) 111 @@lock.synchronize do 112 @@properties.delete(name.to_sym) 113 end 114 end
Return specified property value.
-
Parameters
- String, Symbol
-
name Property name to return value
-
Returns
- ANY
-
Specified property value
-
Errors
# File lib/core/config/collection.rb 75 def self.get(name) 76 value = nil 77 @@lock.synchronize do 78 value = @@properties[name.to_sym] 79 end 80 value 81 end
Dump properties to disk.
This class was originally designed as a logging mechanism so it is focused on providing write methods so far. Notice the missing load() method.
The property dump must be explicitly enabled with the :config_store option.
TODO:
-
This method will undergo a large’ish transformation in the future as it is rewritten to make it more flexible.
-
Throw appropriate error if write fails.
-
Parameters
Hash
<Symbol|ANY>-
options Method options
- String
-
:log_dir Directory to store the log files
- String
-
:log_name Name of the log file (*no dot or extension*)
- Boolean
-
:config_store Check whether configurations should be stored
-
Returns
- Void
-
This method does not currently have a return value
-
Errors
See also:
# File lib/core/config/collection.rb 160 def self.save(options = {}) 161 unless Util::Data.empty?(options[:log_dir]) 162 @@lock.synchronize do 163 log_dir = options[:log_dir] 164 165 log_name = options[:log_name] 166 log_name = 'properties' unless log_name 167 168 if options[:config_store] 169 unless File.directory?(log_dir) 170 FileUtils.mkdir_p(log_dir) 171 end 172 Util::Disk.write(File.join(log_dir, "#{log_name}.json"), Util::Data.to_json(@@properties, true)) 173 Util::Disk.write(File.join(log_dir, "#{log_name}.yaml"), Util::Data.to_yaml(Util::Data.string_map(@@properties))) 174 end 175 end 176 end 177 end
Set property value.
-
Parameters
- String, Symbol
-
name Property name to set value
- ANY
-
value Specified property value
-
Returns
- Void
-
This method does not currently have a return value
-
Errors
# File lib/core/config/collection.rb 94 def self.set(name, value) 95 @@lock.synchronize do 96 @@properties[name.to_sym] = value 97 end 98 end