class ActsAsTaggableOnMongoid::TagList
:reek: MissingSafeMethod :reek: SubclassedFromCoreClass
Attributes
:reek: Attribute
Public Class Methods
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 45 def initialize(tag_definition, *args) @tag_definition = tag_definition add(*args) end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 52 def new_taggable_list(tag_definition, taggable) list = ActsAsTaggableOnMongoid::TagList.new(tag_definition) list.taggable = taggable list end
Public Instance Methods
Concatenation — Returns a new tag list built by concatenating the two tag lists together to produce a third tag list.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 120 def +(other) dup.add(other) end
Removal — Returns a new tag list built by removing the passed in tag list to produce a third tag list.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 126 def -(other) dup.remove(other) end
Append—Add the tag to the tag_list. This expression returns the tag_list itself, so several appends may be chained together.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 114 def <<(obj) add(obj) end
:reek: ManualDispatch
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 195 def ==(other) if tag_definition.preserve_tag_order? super elsif other.respond_to?(:sort) self&.sort == other.sort end end
Add tags to the tag_list. Duplicate or blank tags will be ignored. Use the :parse
option to add an unparsed tag string.
Example:
tag_list.add("Fun", "Happy") tag_list.add("Fun, Happy", :parse => true)
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 92 def add(*names) names = extract_and_apply_options!(names) concat(names) clean! self end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 203 def add_tagging(tagging) orig_taggable = taggable @taggable = nil begin tag = tagging.tag_name self << tag unless include?(tag) ensure @taggable = orig_taggable end end
Appends the elements of other_tag_list
to self
.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 140 def clear notify_will_change super self end
Appends the elements of other_tag_list
to self
.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 131 def concat(other_tag_list) notify_will_change super(other_tag_list).send(:clean!) self end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 61 def dup list = ActsAsTaggableOnMongoid::TagList.new(tag_definition, *self) list.tagger = instance_variable_get(:@tagger) if instance_variable_defined?(:@tagger) list.taggable = taggable list end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 188 def notify_will_change return unless taggable taggable.tag_list_on_changed tag_definition end
Remove specific tags from the tag_list. Use the :parse
option to add an unparsed tag string.
Example:
tag_list.remove("Sad", "Lonely") tag_list.remove("Sad, Lonely", :parse => true)
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 167 def remove(*names) remove_list = ActsAsTaggableOnMongoid::TagList.new(tag_definition, *names) notify_will_change delete_if { |name| remove_list.include?(name) } self end
Replaces the tags with the tags passed in.
Example:
tag_list.set("Fun", "Happy") tag_list.set("Fun, Happy", :parse => true)
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 106 def set(*names) clear add(*names) end
Appends the elements of other_tag_list
to self
.
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 149 def silent_concat(other_tag_list) temp_taggable = taggable self.taggable = nil concat(other_tag_list) self.taggable = temp_taggable self end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 75 def tagger return nil unless tag_definition.tagger? return tag_definition.default_tagger(taggable) unless instance_variable_defined?(:@tagger) tagger = instance_variable_get(:@tagger) tagger = taggable&.public_send(tagger) if tagger.is_a?(Symbol) instance_variable_set(:@tagger, tagger) end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 69 def tagger=(value) return unless tag_definition.tagger? instance_variable_set(:@tagger, value) end
Transform the tag_list into a tag string suitable for editing in a form. The tags are joined with TagList.delimiter
and quoted if necessary.
Example:
tag_list = TagList.new("Round", "Square,Cube") tag_list.to_s # 'Round, "Square,Cube"'
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 184 def to_s tag_definition.parser.new(*self).to_s end
Private Instance Methods
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 218 def clean! reject!(&:blank?) map!(&:to_s) map!(&:strip) conditional_clean_rules end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 227 def conditional_clean_rules map! { |tag| tag.mb_chars.downcase.to_s } if tag_definition.force_lowercase? map!(&:parameterize) if tag_definition.force_parameterize? uniq! self end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 236 def extract_and_apply_options!(args) dup_args = args.dup options = dup_args.extract_options!.dup options.assert_valid_keys :parse, :parser, :tagger instance_variable_set(:@tagger, options[:tagger]) if options.key?(:tagger) && tag_definition.tagger? parse_args_values(dup_args, options) end
# File lib/acts_as_taggable_on_mongoid/tag_list.rb, line 247 def parse_args_values(dup_args, options) options_parser = options[:parser] run_parser = options_parser || tag_definition.parser dup_args.flatten! dup_args.map! { |argument| run_parser.new(argument).parse } if options[:parse] || options_parser dup_args.flatten! dup_args end