Sha256: cc84b74a8b2d1e4531d63dfe0bcbacc6171acef00045d7bd4ef309bfdf6befd6
Contents?: true
Size: 722 Bytes
Versions: 215
Compression:
Stored size: 722 Bytes
Contents
# frozen_string_literal: true module Motor module Tags module_function def assign_tags(taggable, tags) return taggable unless tags tags.each do |tag_name| next if taggable.taggable_tags.find { |tt| tt.tag.name.casecmp(tag_name).zero? } tag = Tag.find_or_initialize_by(name: tag_name) taggable.taggable_tags.new(tag: tag) end remove_missing_tags(taggable, tags) if taggable.persisted? taggable end def remove_missing_tags(taggable, tags) downcase_tags = tags.map(&:downcase) tags_to_remove = taggable.tags.reject { |tt| tt.name.downcase.in?(downcase_tags) } taggable.tags -= tags_to_remove taggable end end end
Version data entries
215 entries across 215 versions & 7 rubygems