class ActsAsMentionable::MentionsUpdater

Attributes

changes[R]
mentioner[R]

Public Class Methods

new(mentioner, changes) click to toggle source
# File lib/acts_as_mentionable/mentions_updater.rb, line 5
def initialize mentioner, changes
  @mentioner = mentioner
  @changes = changes
end

Public Instance Methods

call() { || ... } click to toggle source
# File lib/acts_as_mentionable/mentions_updater.rb, line 10
def call
  Mention.transaction do
    remove_old_mentionables
    add_new_mentionables
    invoke_mentions_updated_callback
    yield if block_given?
  end
end

Private Instance Methods

add_new_mentionables() click to toggle source
# File lib/acts_as_mentionable/mentions_updater.rb, line 25
def add_new_mentionables
  Mention.add_mentionables_for_mentioner mentioner, changes[:added] unless changes[:added].empty?
end
invoke_mentions_updated_callback() click to toggle source
# File lib/acts_as_mentionable/mentions_updater.rb, line 29
def invoke_mentions_updated_callback
  TransactionCallbacks.on_committed do
    ActsAsMentionable.mentions_updated_callback.call mentioner, changes
  end
end
remove_old_mentionables() click to toggle source
# File lib/acts_as_mentionable/mentions_updater.rb, line 21
def remove_old_mentionables
  Mention.remove_mentionables_for_mentioner mentioner, changes[:removed] unless changes[:removed].empty?
end