Class: Rdm::ConfigValidator
- Inherits:
-
Object
- Object
- Rdm::ConfigValidator
- Defined in:
- lib/rdm/yml_config/config_validator.rb
Instance Method Summary collapse
-
#initialize(env_config) ⇒ ConfigValidator
constructor
A new instance of ConfigValidator.
- #validate!(hash_config) ⇒ Object
Constructor Details
#initialize(env_config) ⇒ ConfigValidator
Returns a new instance of ConfigValidator.
4 5 6 |
# File 'lib/rdm/yml_config/config_validator.rb', line 4 def initialize(env_config) @env_config = env_config end |
Instance Method Details
#validate!(hash_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rdm/yml_config/config_validator.rb', line 8 def validate!(hash_config) dto = OpenStruct.new(hash_config) if @env_config.is_hash? @env_config.children.each do |subconfig| self.class.new(subconfig).validate!(dto.send(@env_config.name).to_h) end elsif @env_config.is_array? dto.send(@env_config.name).each do |el| array_dto = OpenStruct.new(@env_config.name => el) validator(@env_config.name, @env_config.children.first.validates.to_hash).validate!(array_dto) end else validator(@env_config.name, @env_config.validates.to_hash).validate!(dto) end dto rescue AttrValidator::Errors::ValidationError => e raise Rdm::Errors::InvalidConfig, e. end |