Class: Activity

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/activity_tracker/activity.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by(user) ⇒ Object


30
31
32
# File 'lib/activity_tracker/activity.rb', line 30

def self.by(user)
  Activity.where("user_id = ?", user.id).count
end

Instance Method Details

#can_be_deleted_by?(user) ⇒ Boolean


34
35
36
37
38
# File 'lib/activity_tracker/activity.rb', line 34

def can_be_deleted_by?(user)
  return false if user.nil?
  return false unless user.admin? || user.moderator? || self.user_id.eql?(user.id)
  true
end

#update_counter_on_userObject


23
24
25
26
27
28
# File 'lib/activity_tracker/activity.rb', line 23

def update_counter_on_user
  if user && user.class.column_names.include?('activities_count')
    new_count =  Activity.by(user)
    user.update_attribute(:activities_count, new_count )
  end
end