Class: SocialActivity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SocialActivity
- Defined in:
- lib/app/models/social_activity.rb
Class Method Summary collapse
- .create_activities(subject, verb, object, options = {}) ⇒ Object
- .exists(subject, verb, object) ⇒ Object
- .objects_by_verb_count(object, verb) ⇒ Object
- .unseen_activities(for_whom) ⇒ Object
Instance Method Summary collapse
Class Method Details
.create_activities(subject, verb, object, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/app/models/social_activity.rb', line 27 def self.create_activities(subject, verb, object, = {}) activities = [] owners = [ subject, object ] owners.concat([:additional_recipients]) if [:additional_recipients] owners.concat(subject..collect {|i| i.source }) owners.concat(object..collect {|i| i.source }) owners.uniq.each do |owner| activities << SocialActivity.create(:owner => owner, :subject => subject, :verb => verb, :target => object, :options_as_json => .to_json) end activities end |
.exists(subject, verb, object) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/app/models/social_activity.rb', line 50 def self.exists(subject, verb, object) SocialActivity.where('subject_id = ? and subject_type = ? and verb = ? ' + 'and target_id = ? and target_type = ?', subject.id, subject.class.name, verb, object.id, object.class.name).exists? end |
.objects_by_verb_count(object, verb) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/app/models/social_activity.rb', line 57 def self.objects_by_verb_count(object, verb) SocialActivity.where('target_id = ? and target_type = ? and verb = ? ' + 'and owner_id = ? and owner_type = ?', object.id, object.class.name, verb, object.id, object.class.name).count end |
.unseen_activities(for_whom) ⇒ Object
44 45 46 47 48 |
# File 'lib/app/models/social_activity.rb', line 44 def self.unseen_activities(for_whom) SocialActivity.where('owner_id = ? and owner_type = ? and unseen = ?', for_whom.id, for_whom.class.name, true).order("created_at DESC") end |
Instance Method Details
#consume ⇒ Object
15 16 17 18 |
# File 'lib/app/models/social_activity.rb', line 15 def consume self.unseen = false self.save end |
#options ⇒ Object
7 8 9 |
# File 'lib/app/models/social_activity.rb', line 7 def JSON.parse end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/app/models/social_activity.rb', line 11 def to_s "SocialActivity #{subject} #{verb} #{target} (owned by #{owner})" end |