Sha256: 1b0ac3eefd612d49a8d82f7b6b38f4a39cc89176c4799c2ffc294dcd756c57ac

Contents?: true

Size: 1.29 KB

Versions: 52

Compression:

Stored size: 1.29 KB

Contents

# This model includes all the actions performed by {Actor actors}
# on {ActivityObject activity objects}
# 
class ActivityAction < ActiveRecord::Base
  include ActiveModel::ForbiddenAttributesProtection

  belongs_to :actor
  belongs_to :activity_object

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

  scope :not_sent_by, lambda{ |actor|
    where(arel_table[:actor_id].not_in(Actor.normalize_id(actor)))
  }

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

  scope :authored_or_owned, where(arel_table[:author].eq(true).
                                or(arel_table[:user_author].eq(true)).
                                or(arel_table[:owner].eq(true)))

  scope :authored_or_owned_by, lambda{ |subject|
    authored_or_owned.sent_by(subject)
  }


  before_create :follow_by_author_and_owner

  after_save :change_follower_count

  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

52 entries across 52 versions & 2 rubygems

Version Path
social_stream-2.2.2 base/app/models/activity_action.rb
social_stream-base-2.2.2 app/models/activity_action.rb
social_stream-2.2.1 base/app/models/activity_action.rb
social_stream-base-2.2.1 app/models/activity_action.rb
social_stream-2.2.0 base/app/models/activity_action.rb
social_stream-base-2.2.0 app/models/activity_action.rb
social_stream-2.1.1 base/app/models/activity_action.rb
social_stream-1.1.12 base/app/models/activity_action.rb
social_stream-base-1.1.11 app/models/activity_action.rb
social_stream-2.1.0 base/app/models/activity_action.rb
social_stream-base-2.1.0 app/models/activity_action.rb
social_stream-2.0.4 base/app/models/activity_action.rb
social_stream-base-2.0.4 app/models/activity_action.rb
social_stream-2.0.3 base/app/models/activity_action.rb
social_stream-base-2.0.3 app/models/activity_action.rb
social_stream-1.1.11 base/app/models/activity_action.rb
social_stream-base-1.1.10 app/models/activity_action.rb
social_stream-1.1.10 base/app/models/activity_action.rb
social_stream-base-1.1.9 app/models/activity_action.rb
social_stream-1.1.9 base/app/models/activity_action.rb