Sha256: 0f57bcd9287db4051a21ebd169a7eaf18ba4d12316b674b3f169e540ac880e16

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module Jackhammer
  class ConfigurationValidator
    attr_accessor :config_yaml, :environment, :errors

    def initialize
      @errors = []
    end

    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

    def validate_environment_defined
      return if config_yaml[environment]

      add_error("Environment '#{environment}' is not defined")
    end

    def validate_topic_exchange_defined
      return if config_yaml[environment].keys.any?

      add_error("Environment '#{environment}' does not define a topic exchange")
    end

    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

    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

    private

    def add_error(str)
      @errors << str
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jackhammer-1.5.1 lib/jackhammer/configuration_validator.rb