object.rb 467 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Tag::Object < ApplicationModel
  3. validates :name, presence: true
  4. =begin
  5. lookup by name and create tag item
  6. tag_object = Tag::Object.lookup_by_name_and_create('some tag')
  7. =end
  8. def self.lookup_by_name_and_create(name)
  9. lookup = name.strip
  10. tag_object = Tag::Object.lookup(name: lookup)
  11. return tag_object if tag_object
  12. Tag::Object.create(name: lookup)
  13. end
  14. end