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)



66
67
68
69
70
# File 'app/models/concerns/shared/tags.rb', line 66

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

#tag_with(keyword_id) ⇒ Object



46
47
48
# File 'app/models/concerns/shared/tags.rb', line 46

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



36
37
38
# File 'app/models/concerns/shared/tags.rb', line 36

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



42
43
44
# File 'app/models/concerns/shared/tags.rb', line 42

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