module ActsAsTaggableOnMongoid::Taggable::ListTags
This module adds methods for tracking tag definitions within Taggable
classes
Public Instance Methods
cleanup_tag_types(tag_types, klass)
click to toggle source
:reek: UtilityFunction
# File lib/acts_as_taggable_on_mongoid/taggable/list_tags.rb, line 37 def cleanup_tag_types(tag_types, klass) return tag_types if tag_types.values.all? { |tag_definition| tag_definition.owner == klass } tag_types.each_with_object({}.with_indifferent_access) do |(key, tag_definition), hash| hash[key] = ActsAsTaggableOnMongoid::Taggable::TagTypeDefinition.copy_from(klass, tag_definition) end end
define_tag(tag_type, options = {})
click to toggle source
In order to allow dynamic tags, return a default tag_definition
for any missing tag_type. This means that any dynamic tag necessarily is created with the current defaults
# File lib/acts_as_taggable_on_mongoid/taggable/list_tags.rb, line 47 def define_tag(tag_type, options = {}) return if tag_type.blank? tag_definition = tag_types[tag_type] return tag_definition if tag_definition # tag_types is a class_attribute # As such, we have to replace it each time with a new array so that inherited classes and instances # are able to maintain separate lists if need be. new_tag_types = {}.with_indifferent_access.merge!(tag_types || {}) self.my_tag_types = new_tag_types tag_definition = new_tag_types[tag_type] = ActsAsTaggableOnMongoid::Taggable::TagTypeDefinition.new(self, tag_type, options) tag_definition.define_cache_field tag_definition.define_base_relations tag_definition.define_relations tag_definition.add_tag_list end
tag_definition(tag_type)
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/list_tags.rb, line 23 def tag_definition(tag_type) return unless tag_type.present? tag_types[tag_type] ||= ActsAsTaggableOnMongoid::Taggable::TagTypeDefinition.new(self, tag_type) end
tag_types()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/list_tags.rb, line 15 def tag_types klass = self.class self.my_tag_types = klass.cleanup_tag_types(my_tag_types, klass) my_tag_types end