Class: Socializer::Person
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Socializer::Person
- Extended by:
- Enumerize
- Includes:
- ObjectTypeBase
- Defined in:
- app/models/socializer/person.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#avatar_url ⇒ Object
TODO: avatar_url - clean this up.
- #circles ⇒ Object
- #comments ⇒ Object
- #contact_of ⇒ Object
- #contacts ⇒ Object
- #groups ⇒ Object
- #likes ⇒ Object
- #likes?(object) ⇒ Boolean
- #memberships ⇒ Object
- #notes ⇒ Object
- #pending_memberships_invites ⇒ Object
- #received_notifications ⇒ Object
- #services ⇒ Object
Methods included from ObjectTypeBase
Class Method Details
.create_with_omniauth(auth) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/models/socializer/person.rb', line 112 def self.create_with_omniauth(auth) create! do |user| user.display_name = auth.info.name user.email = auth.info.email image_url = auth.info.image if image_url.nil? image_url = '' user.avatar_provider = 'GRAVATAR' else user.avatar_provider = auth.provider.upcase end user.authentications.build(provider: auth.provider, uid: auth.uid, image_url: image_url) end end |
Instance Method Details
#avatar_url ⇒ Object
TODO: avatar_url - clean this up
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/socializer/person.rb', line 90 def avatar_url avatar_provider_array = %w( FACEBOOK LINKEDIN TWITTER ) if avatar_provider_array.include?(avatar_provider) provider = avatar_provider.downcase authentications.where(provider: provider).first.try(:image_url) else return if email.blank? "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.downcase)}" end # if avatar_provider == 'FACEBOOK' # authentications.where(provider: 'facebook')[0].image_url if authentications.where(provider: 'facebook')[0].present? # elsif avatar_provider == 'TWITTER' # authentications.where(provider: 'twitter')[0].image_url if authentications.where(provider: 'twitter')[0].present? # elsif avatar_provider == 'LINKEDIN' # authentications.where(provider: 'linkedin')[0].image_url if authentications.where(provider: 'linkedin')[0].present? # else # "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.downcase)}" if email.present? # end end |
#circles ⇒ Object
34 35 36 |
# File 'app/models/socializer/person.rb', line 34 def circles @circles ||= activity_object.circles end |
#comments ⇒ Object
38 39 40 |
# File 'app/models/socializer/person.rb', line 38 def comments @comments ||= activity_object.comments end |
#contact_of ⇒ Object
62 63 64 |
# File 'app/models/socializer/person.rb', line 62 def contact_of @contact_of ||= Circle.joins { ties }.where { ties.contact_id.eq my { guid } }.map { |circle| circle. }.uniq end |
#contacts ⇒ Object
58 59 60 |
# File 'app/models/socializer/person.rb', line 58 def contacts @contacts ||= circles.map { |c| c.contacts }.flatten.uniq end |
#groups ⇒ Object
46 47 48 |
# File 'app/models/socializer/person.rb', line 46 def groups @groups ||= activity_object.groups end |
#likes ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'app/models/socializer/person.rb', line 66 def likes activity_obj_id = activity_object.id verbs_of_interest = %w(like unlike) verbs_of_interest = Verb.where { name.in(verbs_of_interest) } query = Activity.group { activity_object_id }.where { verb_id.in(verbs_of_interest) & actor_id.eq(activity_obj_id) & target_id.eq(nil) }.having('COUNT(1) % 2 == 1') @likes ||= query end |
#likes?(object) ⇒ Boolean
75 76 77 78 79 80 81 82 |
# File 'app/models/socializer/person.rb', line 75 def likes?(object) activity_obj_id = activity_object.id verbs_of_interest = %w(like unlike) verbs_of_interest = Verb.where { name.in(verbs_of_interest) } query = Activity.where { verb_id.in(verbs_of_interest) & activity_object_id.eq(object.id) & actor_id.eq(activity_obj_id) } query.size.odd? end |
#memberships ⇒ Object
50 51 52 |
# File 'app/models/socializer/person.rb', line 50 def memberships @memberships ||= activity_object.memberships end |
#notes ⇒ Object
42 43 44 |
# File 'app/models/socializer/person.rb', line 42 def notes @notes ||= activity_object.notes end |
#pending_memberships_invites ⇒ Object
84 85 86 87 |
# File 'app/models/socializer/person.rb', line 84 def pending_memberships_invites privacy_private = Group.privacy_level.find_value(:private).value @pending_memberships_invites ||= Membership.joins { group }.where { member_id.eq(my { guid }) & active.eq(false) & group.privacy_level.eq(privacy_private) } end |
#received_notifications ⇒ Object
54 55 56 |
# File 'app/models/socializer/person.rb', line 54 def received_notifications @notifications ||= activity_object.notifications end |
#services ⇒ Object
30 31 32 |
# File 'app/models/socializer/person.rb', line 30 def services @services ||= authentications.where { provider.not_eq('Identity') } end |