Module: E9Tags::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/e9_tags/model.rb

Defined Under Namespace

Modules: DelayedClassMethods

Instance Method Summary collapse

Instance Method Details

#clear_all_tagsObject

this won’t take unless the record is saved successfully



69
70
71
# File 'lib/e9_tags/model.rb', line 69

def clear_all_tags
  tagging_contexts.each {|context| set_tag_list_on(context, '') }
end

#has_tags?Boolean

It should be noted that our usage of tag contexts is apparently incongruent with acts_as_taggable_on’s intentions. It goes to lengths to write class methods for each context with the apparent intention that these be used separately, whereas we needed contexts to be more dynamic (all contexts but “tags” are user defined).

The gem provides custom contexts but they’re not very well supported and somewhat broken (see #tagging_contexts below).

Because of the way AATO expects contexts to be used, it makes some assumptions, and writes a bunch of helper methods to the class for each. These are useless to us really and only serve to add some confusion to the scope. E.g. for acts_as_taggable_on :tags (the default), the following methods are created:

tag_taggings (has_many) tags (has_many) tags_list tags_list= all_tags_list

It’s important to note that these methods all only deal with the “tags” context and won’t return any tag which does not have it.

The actual associations on the taggable record are “taggings” and “base_tags”, which ignores context, returning all tags.

Returns:

  • (Boolean)


34
35
36
# File 'lib/e9_tags/model.rb', line 34

def has_tags?
  !base_tags.empty?
end

#tag_lists=(hash) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/e9_tags/model.rb', line 73

def tag_lists=(hash)
  self.clear_all_tags
  hash.each do |context, tags|
    c = context.to_s.sub(/_tag_list$/, '')
    c = E9Tags.escape_context(c)

    self.set_tag_list_on(c, tags)
  end
end