Sha256: e8b9b72c464ae588f6b97005e6ab2c34e3b9117354fc2aed54b2c2eea6ae7adb
Contents?: true
Size: 714 Bytes
Versions: 21
Compression:
Stored size: 714 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.downcase == tag_name.downcase } tag = Tag.where('lower(name) = ?', tag_name.downcase).take || Tag.new(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) tags_to_remove = taggable.tags.reject { |tt| tt.name.downcase.in?(tags) } taggable.tags -= tags_to_remove taggable end end end
Version data entries
21 entries across 21 versions & 1 rubygems