class ActsAsTaggableOnMongoid::Taggable::Utils::TagListDiff
:reek: TooManyInstanceVariables :reek: InstanceVariableAssumption
Attributes
tag_definition[R]
Public Class Methods
new(tag_definition:, tags:, current_tags:)
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 18 def initialize(tag_definition:, tags:, current_tags:) @tag_definition = tag_definition @tags = tags @current_tags = current_tags.map(&:tag).compact @old_tags = {} @new_tags = {} end
Public Instance Methods
call()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 27 def call @old_tags = current_tags - tags @new_tags = tags - current_tags preserve_tag_list_order end
Private Instance Methods
first_ordered_difference()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 107 def first_ordered_difference return @first_ordered_difference if defined?(@first_ordered_difference) index = 0 while index < shared_tags.length break unless shared_tags[index] == tags[index] index += 1 end @first_ordered_difference = index end
ignore_tagging_error(tagging)
click to toggle source
:reek: UtilityFunction ignore the error if it is that the tagging already exists.
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 69 def ignore_tagging_error(tagging) tagging_errors = tagging.errors tagging_errors.count == 1 && tagging.tag_name.present? && tagging.tag.present? && (tagging_errors.key?(:tag_name) || tagging_errors.key?(:tag_id)) end
preserve_new_tag_list_order()
click to toggle source
:reek: NestedIterators
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 96 def preserve_new_tag_list_order # Order the array of tag objects to match the tag list @new_tags = tags.map do |tag| preserved_tags.detect { |preserved_tag| preserved_tag.name == tag.name && preserved_tag.owner == tag.owner } end.compact end
preserve_tag_list_order()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/utils/tag_list_diff.rb, line 78 def preserve_tag_list_order return unless tag_definition.preserve_tag_order? @shared_tags = current_tags & tags return if share_tags_sorted? # Update arrays of tag objects @old_tags |= current_tags[first_ordered_difference..-1] preserve_new_tag_list_order end