Sha256: 67dcb97c5b1b66d14e70cfcaad3e90098ced338d2187811e9df709be6827ac12

Contents?: true

Size: 868 Bytes

Versions: 4

Compression:

Stored size: 868 Bytes

Contents

# This model includes all the actions performed by {Actor actors}
# on {ActivityObject activity objects}
# 
class ActivityAction < ActiveRecord::Base
  belongs_to :actor
  belongs_to :activity_object

  before_save :change_follower_count

  scope :sent_by, lambda{ |actor|
    where(:actor_id => Actor.normalize_id(actor))
  }

  scope :received_by, lambda{ |activity_object|
    where(:activity_object_id => ActivityObject.normalize_id(activity_object))
  }

  before_create :follow_by_author_and_owner

  private

  # Updates the follower_count counter in the {ActivityObject}
  def change_follower_count
    return unless follow_changed?

    follow? ?
      activity_object.increment!(:follower_count) :
      activity_object.decrement!(:follower_count)
  end

  def follow_by_author_and_owner
    self.follow = true if author? || user_author? || owner?
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
social_stream-0.25.1 base/app/models/activity_action.rb
social_stream-base-0.19.1 app/models/activity_action.rb
social_stream-0.25.0 base/app/models/activity_action.rb
social_stream-base-0.19.0 app/models/activity_action.rb