Class: Jackhammer::ConfigurationValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/jackhammer/configuration_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurationValidator

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_yamlObject

Returns the value of attribute config_yaml.



3
4
5
# File 'lib/jackhammer/configuration_validator.rb', line 3

def config_yaml
  @config_yaml
end

#environmentObject

Returns the value of attribute environment.



3
4
5
# File 'lib/jackhammer/configuration_validator.rb', line 3

def environment
  @environment
end

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/jackhammer/configuration_validator.rb', line 3

def errors
  @errors
end

Instance Method Details

#validateObject



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_definedObject



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_definedObject



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_definedObject



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_definedObject



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