Sha256: 81fb34e0ec858e8631df5059eeb221c27d6b03d492314feb758f3900efd694b3

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

module ForemanNameGenerator
  module HostExtensions
    extend ActiveSupport::Concern

    included do
      attr_accessor :generated_random_name
      before_validation :generate_name
    end

    def generate_name
      if (self.name.nil? || self.name.empty?) && new_record? && (Setting['name_generator_type'] == 'MAC' || Setting['name_generator_type'] == 'MAC+RANDOM')
        generator = ForemanNameGenerator::MacGenerator.new
        self.name = generator.generate(self.mac).join('-').downcase
      end
      if (self.name.nil? || self.name.empty?) && new_record? && (Setting['name_generator_type'] == 'RANDOM' || Setting['name_generator_type'] == 'MAC+RANDOM')
        self.generated_random_name = self.name = Setting::NameGenerator.next_generated_name.join('-').downcase
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
foreman_name_generator-0.0.2 app/models/concerns/foreman_name_generator/host_extensions.rb
foreman_name_generator-0.0.1 app/models/concerns/foreman_name_generator/host_extensions.rb