Module: Shared::Tags

Overview

Shared code for extending data classes with Tags.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#reject_tags(attributed) ⇒ Object (private)



52
53
54
55
56
# File 'app/models/concerns/shared/tags.rb', line 52

def reject_tags(attributed)
  (attributed['keyword'].blank? && attributed['keyword_id'].blank?) &&
    attributed['position'].blank? &&
    attributed['keyword_attributes'].blank?
end

#tag_with(keyword_id) ⇒ Object



31
32
33
# File 'app/models/concerns/shared/tags.rb', line 31

def tag_with(keyword_id)
  tags << Tag.new(keyword_id:)
end

#tagged?Boolean

Returns true if the object has tags.

Returns:

  • (Boolean)

    true if the object has tags



21
22
23
# File 'app/models/concerns/shared/tags.rb', line 21

def tagged?
  tags.any?
end

#tagged_with?(keyword_id) ⇒ Boolean

Returns true if the object has a tak with this keyword.

Returns:

  • (Boolean)

    true if the object has a tak with this keyword



27
28
29
# File 'app/models/concerns/shared/tags.rb', line 27

def tagged_with?(keyword_id)
  tags.where(keyword_id:).any?
end