Class: Jackhammer::ConfigurationValidator
- Inherits:
-
Object
- Object
- Jackhammer::ConfigurationValidator
- Defined in:
- lib/jackhammer/configuration_validator.rb
Instance Attribute Summary collapse
-
#config_yaml ⇒ Object
Returns the value of attribute config_yaml.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize ⇒ ConfigurationValidator
constructor
A new instance of ConfigurationValidator.
- #validate ⇒ Object
- #validate_environment_defined ⇒ Object
- #validate_handlers_defined ⇒ Object
- #validate_queues_defined ⇒ Object
- #validate_topic_exchange_defined ⇒ Object
Constructor Details
#initialize ⇒ ConfigurationValidator
Returns a new instance of ConfigurationValidator.
5 6 7 |
# File 'lib/jackhammer/configuration_validator.rb', line 5 def initialize @errors = [] end |
Instance Attribute Details
#config_yaml ⇒ Object
Returns the value of attribute config_yaml.
3 4 5 |
# File 'lib/jackhammer/configuration_validator.rb', line 3 def config_yaml @config_yaml end |
#environment ⇒ Object
Returns the value of attribute environment.
3 4 5 |
# File 'lib/jackhammer/configuration_validator.rb', line 3 def environment @environment end |
#errors ⇒ Object
Returns the value of attribute errors.
3 4 5 |
# File 'lib/jackhammer/configuration_validator.rb', line 3 def errors @errors end |
Instance Method Details
#validate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/jackhammer/configuration_validator.rb', line 9 def validate validate_environment_defined return if errors.any? validate_topic_exchange_defined return if errors.any? validate_queues_defined return if errors.any? validate_handlers_defined end |
#validate_environment_defined ⇒ Object
22 23 24 25 26 |
# File 'lib/jackhammer/configuration_validator.rb', line 22 def validate_environment_defined return if config_yaml[environment] add_error("Environment '#{environment}' is not defined") end |
#validate_handlers_defined ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/jackhammer/configuration_validator.rb', line 47 def validate_handlers_defined config_yaml[environment].each do |exchange_name, exchange_config| exchange_config['queues'].each do |qconfig| Object.const_get(qconfig['handler']) rescue NameError add_error("Uninitialized constant #{qconfig['handler']}") end end end |
#validate_queues_defined ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jackhammer/configuration_validator.rb', line 34 def validate_queues_defined topics = config_yaml[environment].keys topics.each do |topic| begin next if config_yaml[environment][topic]['queues'] rescue StandardError false end add_error("Topic '#{topic}' does not define any queues") end end |
#validate_topic_exchange_defined ⇒ Object
28 29 30 31 32 |
# File 'lib/jackhammer/configuration_validator.rb', line 28 def validate_topic_exchange_defined return if config_yaml[environment].keys.any? add_error("Environment '#{environment}' does not define a topic exchange") end |