class ActsAsTaggableOnMongoid::TaggerTagList

:reek: RepeatedConditional

Attributes

tag_definition[R]
taggable[R]
tagger_tag_lists[R]

Public Class Methods

new(tag_definition, taggable) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 27
def initialize(tag_definition, taggable)
  @tag_definition = tag_definition
  @taggable       = taggable

  @tagger_tag_lists = Hash.new { ActsAsTaggableOnMongoid::TagList.new_taggable_list(tag_definition, taggable) }
end

Public Instance Methods

<=>(other) click to toggle source
Calls superclass method
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 53
def <=>(other)
  compact!

  if other.is_a?(ActsAsTaggableOnMongoid::TagList)
    compare_to_tag_list(other)
  elsif other.is_a?(ActsAsTaggableOnMongoid::TaggerTagList)
    other.compact!

    compare_to_tagger_tag_list(other)
  else
    super(other)
  end
end
[](tagger) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 67
def [](tagger)
  list = tagger_tag_lists[tagger]

  list.tagger = tagger

  tagger_tag_lists[tagger] = list
end
[]=(tagger, value) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 75
def []=(tagger, value)
  tagger_list = self[tagger]

  if value.is_a?(ActsAsTaggableOnMongoid::TagList)
    tagger_list.set(value)
  else
    value           = Array.wrap(value).dup
    options         = value.extract_options!
    options[:parse] = options.fetch(:parse) { true }

    value = [*value, options]

    tagger_list.set(*value)
  end
end
blank?() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 115
def blank?
  tagger_tag_lists.values.all?(&:blank?)
end
compact() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 39
def compact
  dup.compact!
end
compact!() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 34
def compact!
  reject! { |_key, value| value.blank? }
  self
end
dup() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 91
def dup
  list = ActsAsTaggableOnMongoid::TaggerTagList.new(tag_definition, taggable)

  each do |tagger, tag_list|
    list[tagger].silent_concat(tag_list) if tag_list.present?
  end

  list
end
flatten() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 43
def flatten
  list = ActsAsTaggableOnMongoid::TagList.new_taggable_list(tag_definition, taggable)

  each_value do |tag_list|
    list.concat(tag_list)
  end

  list
end
notify_will_change() click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 109
def notify_will_change
  return unless taggable

  taggable.tag_list_on_changed tag_definition
end
taggable=(value) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 101
def taggable=(value)
  @taggable = value

  tagger_tag_lists.each_value do |tag_list|
    tag_list.taggable = taggable
  end
end

Private Instance Methods

compare_tag_list_properties(other) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 149
def compare_tag_list_properties(other)
  sub_compare = tagger_tag_lists.length <=> 1
  return sub_compare unless sub_compare&.zero?

  sub_compare = keys.first <=> other.tagger
  return sub_compare unless sub_compare&.zero?

  taggable <=> other.taggable
end
compare_tagger_tag_list_properties(other) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 123
def compare_tagger_tag_list_properties(other)
  sub_compare = keys.length <=> other.keys.length
  return sub_compare unless sub_compare&.zero?

  taggable <=> other.taggable
end
compare_to_tag_list(other) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 159
def compare_to_tag_list(other)
  sub_compare = compare_tag_list_properties(other)
  return sub_compare unless sub_compare&.zero?

  tagger_list = values.first
  if tag_definition.preserve_tag_order
    tagger_list <=> other
  else
    tagger_list.sort <=> other.sort
  end
end
compare_to_tagger_tag_list(other) click to toggle source
# File lib/acts_as_taggable_on_mongoid/tagger_tag_list.rb, line 130
def compare_to_tagger_tag_list(other)
  sub_compare = compare_tagger_tag_list_properties(other)
  return sub_compare unless sub_compare&.zero?

  any? do |key, tag_list|
    other_tag_list = other[key]

    sub_compare = if tag_definition.preserve_tag_order
                    tag_list <=> other_tag_list
                  else
                    tag_list.sort <=> other_tag_list.sort
                  end

    !sub_compare&.zero?
  end

  sub_compare
end