Class: Pressroom::Tag

Inherits:
ApplicationRecord show all
Includes:
Sluggable
Defined in:
app/models/pressroom/tag.rb

Constant Summary

Constants included from Sluggable

Sluggable::FALLBACK_SLUG

Class Method Summary collapse

Class Method Details

.for_names(names) ⇒ Object

Finds or creates one tag per distinct non-blank name.



16
17
18
19
20
21
22
# File 'app/models/pressroom/tag.rb', line 16

def self.for_names(names)
  Array(names)
    .map { |name| name.to_s.strip }
    .reject(&:empty?)
    .uniq
    .map { |name| find_or_create_by!(slug: slugify(name)) { |tag| tag.name = name } }
end