Sha256: 41f043a7900d67097bb7154992d2497388a97015b5f4e06ca5237eda83764ca8

Contents?: true

Size: 634 Bytes

Versions: 9

Compression:

Stored size: 634 Bytes

Contents

module Katello
  module Ext
    module LabelFromName
      def self.included(base)
        base.class_eval do
          before_validation :setup_label_from_name
          validate :label_not_changed, :on => :update
        end
      end

      def setup_label_from_name
        unless label.present?
          self.label = Util::Model.labelize(name)
          if self.class.where(:label => self.label).any?
            self.label = Util::Model.uuid
          end
        end
      end

      def label_not_changed
        if label_changed?
          errors.add(:label, _("cannot be changed."))
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/models/katello/ext/label_from_name.rb
katello-2.4.4 app/models/katello/ext/label_from_name.rb
katello-2.4.3 app/models/katello/ext/label_from_name.rb
katello-2.4.2 app/models/katello/ext/label_from_name.rb
katello-2.4.1 app/models/katello/ext/label_from_name.rb
katello-2.4.0 app/models/katello/ext/label_from_name.rb
katello-2.4.0.rc3 app/models/katello/ext/label_from_name.rb
katello-2.4.0.rc2 app/models/katello/ext/label_from_name.rb
katello-2.4.0.rc1 app/models/katello/ext/label_from_name.rb