Sha256: a36ac5adea479958413b1fa63a26f5efa9ae744fdbd812ac2932b25b088e6949

Contents?: true

Size: 1.24 KB

Versions: 14

Compression:

Stored size: 1.24 KB

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

  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

14 entries across 14 versions & 2 rubygems

Version Path
social_stream-0.30.2 base/app/models/activity_action.rb
social_stream-base-0.24.2 app/models/activity_action.rb
social_stream-0.30.1 base/app/models/activity_action.rb
social_stream-base-0.24.1 app/models/activity_action.rb
social_stream-0.30.0 base/app/models/activity_action.rb
social_stream-base-0.24.0 app/models/activity_action.rb
social_stream-0.29.0 base/app/models/activity_action.rb
social_stream-base-0.23.0 app/models/activity_action.rb
social_stream-0.28.4 base/app/models/activity_action.rb
social_stream-base-0.22.4 app/models/activity_action.rb
social_stream-0.28.1 base/app/models/activity_action.rb
social_stream-base-0.22.1 app/models/activity_action.rb
social_stream-0.28.0 base/app/models/activity_action.rb
social_stream-base-0.22.0 app/models/activity_action.rb