Module: TagAble
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/app/models/concerns/tag_able.rb
Overview
Public: Support taggable entities
Instance Method Summary collapse
-
#sync_tags(updated_tags) ⇒ Object
abstract
First update what is from the updated tags Then delete any that are no longer associated with them.
- #tag_value(key, default = nil) ⇒ Object
Instance Method Details
#sync_tags(updated_tags) ⇒ Object
This method is abstract.
Update the tags associated with the model
First update what is from the updated tags Then delete any that are no longer associated with them
20 21 22 23 24 25 26 27 |
# File 'lib/app/models/concerns/tag_able.rb', line 20 def () .each do |t| tag = .where(key: t.key).first_or_initialize(key: t.key, model: self) tag.update! value: t.value end keys = .map(&:key) .each { |t| t.destroy unless keys.include?(t.key) } end |
#tag_value(key, default = nil) ⇒ Object
29 30 31 32 33 |
# File 'lib/app/models/concerns/tag_able.rb', line 29 def tag_value(key, default = nil) .find_by(key: key.to_s).value rescue StandardError default end |