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)



61
62
63
64
65
# File 'app/models/concerns/shared/tags.rb', line 61

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

#tag_with(keyword_id) ⇒ Object



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

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

#tagged?Boolean

Returns true if the object has tags

Returns:

  • (Boolean)

    true if the object has tags



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

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



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

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