Project

General

Profile

Revision 2b80fdd9

Added by Ori Rabin almost 6 years ago

Fixes #13043 - Change Parameter inheritance to DockerParameter

View differences:

app/models/concerns/foreman_docker/parameter_validators.rb
1 1
module ForemanDocker
2 2
  module ParameterValidators
3 3
    extend ActiveSupport::Concern
4
    include ::ParameterValidators
5 4

  
6
    def parameters_symbol
7
      return :environment_variables if is_a? Container
8
      super
5
    included do
6
      validate :validate_unique_parameter_keys
7
    end
8

  
9
    def validate_unique_parameter_keys
10
      parameters_symbol = [:environment_variables, :exposed_ports, :dns]
11
      parameters_symbol.each do |param_symbol|
12
        keys  = []
13
        errors = false
14

  
15
        self.public_send(param_symbol).each do |param|
16
          errors = duplicate_key?(keys, param)
17
        end
18

  
19
        self.errors[param_symbol] = _('Please ensure the following parameters are unique') if errors
20
      end
21
    end
22

  
23
    def duplicate_key?(keys, param)
24
      if keys.include?(param.key)
25
        param.errors[:key] = _('has already been taken')
26
        return true
27
      else
28
        keys << param.key
29
      end
30

  
31
      false
9 32
    end
10 33
  end
11 34
end

Also available in: Unified diff