Class: RubyUtils::Configuration::BaseConfigurationRepository
- Inherits:
-
Object
- Object
- RubyUtils::Configuration::BaseConfigurationRepository
- Defined in:
- lib/ruby_utils/configuration/base_configuration_repository.rb
Overview
Abstract configuration repository to store the valid configuration parameter. Will raise an NotImplementedError if the abstract methods are called without an implementation in a child class
Instance Attribute Summary collapse
-
#config_hash ⇒ Hash
readonly
The hash with the hashes of the given json file.
Instance Method Summary collapse
-
#check_config_keys ⇒ Object
private
method to check if the required keys are available in the json hash and check for optional ones method.
-
#initialize(config_path) ⇒ BaseConfigurationRepository
constructor
initialization.
-
#required_config_key_available?(key) ⇒ Boolean
private
method to check if the required is present in the hash.
Constructor Details
#initialize(config_path) ⇒ BaseConfigurationRepository
initialization
18 19 20 21 |
# File 'lib/ruby_utils/configuration/base_configuration_repository.rb', line 18 def initialize(config_path) @config_hash = JSON.load(File.read(config_path)) check_config_keys end |
Instance Attribute Details
#config_hash ⇒ Hash (readonly)
Returns the hash with the hashes of the given json file.
14 15 16 |
# File 'lib/ruby_utils/configuration/base_configuration_repository.rb', line 14 def config_hash @config_hash end |
Instance Method Details
#check_config_keys ⇒ Object (private)
method to check if the required keys are available in the json hash and check for optional ones method
29 30 31 32 |
# File 'lib/ruby_utils/configuration/base_configuration_repository.rb', line 29 def check_config_keys fail NotImplementedError, " Error: the subclass #{self.class} needs " \ "to implement the method: process_argument from its base class".red end |
#required_config_key_available?(key) ⇒ Boolean (private)
method to check if the required is present in the hash
37 38 39 40 41 42 |
# File 'lib/ruby_utils/configuration/base_configuration_repository.rb', line 37 def required_config_key_available?(key) if (@config_hash[key] == nil) raise KeyError, "Required parameter #{key} is not present in configuration file." end nil end |