Class: Notifier
- Inherits:
-
Object
- Object
- Notifier
- Defined in:
- app/lib/notifier.rb
Overview
This class is used to find unapproved information in the database and bundle it in a manner that the frontend can parse effectively.
Class Method Summary (collapse)
-
+ (Object) admin_notifications
finds all unapproved admins, pushes admin + user info.
-
+ (Object) all_notifications
helper class to gather all notifications.
-
+ (Object) mentored(unapproved_mentorships)
helper method used to build the mentorships where the person was the mentor.
-
+ (Object) mentors(unapproved_mentorships)
helper method used to gather the persons mentors.
-
+ (Object) mentorship_notifications
finds all unapproved mentorships between approved people reflects mentorships between existing people.
-
+ (Object) person_notifications
this method will bundle all relationships + information w.r.t.
-
+ (Object) supervised(unapproved_supervisions)
helper method used to build supervisions for unapproved person where the person was the supervisor.
-
+ (Object) supervision_notifications
return supervision_notifications for approved people this reflects a relationship between existing people.
-
+ (Object) supervisors(unapproved_supervisions)
helper method for building the person notification where they were supervised.
-
+ (Object) user_notifications
finds all unapproved users.
Class Method Details
+ (Object) admin_notifications
finds all unapproved admins, pushes admin + user info
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/lib/notifier.rb', line 28 def self.admin_notifications @unapproved_admins = Admin.where({:approved => false}) .includes(:user) @res_array = Array.new @unapproved_admins.each do |a| if a.approved == false @admin = { 'id' => a.id, 'user' => a.user } @res_array.push(@admin) end end return @res_array end |
+ (Object) all_notifications
helper class to gather all notifications
6 7 8 9 10 11 12 13 14 |
# File 'app/lib/notifier.rb', line 6 def self.all_notifications return { 'user_notifications' => self.user_notifications, 'admin_notifications' => self.admin_notifications, 'mentorship_notifications' => self.mentorship_notifications, 'supervision_notifications' => self.supervision_notifications, 'person_notifications' => self.person_notifications } end |
+ (Object) mentored(unapproved_mentorships)
helper method used to build the mentorships where the person was the mentor
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'app/lib/notifier.rb', line 205 def self.mentored(unapproved_mentorships) @mentorships = Array.new unapproved_mentorships.each do |m| @mentorships_obj = { 'mentorship' => m, 'instituiton' => m.institution, 'mentored' => { 'person' => m.person, 'institution' => m.person.institution } } @mentorships.push(@mentorships_obj) end return @mentorships end |
+ (Object) mentors(unapproved_mentorships)
helper method used to gather the persons mentors
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/lib/notifier.rb', line 187 def self.mentors(unapproved_mentorships) @mentorships = Array.new unapproved_mentorships.each do |m| @mentorships_obj = { 'mentorship' => m, 'instituiton' => m.institution, 'mentor' => { 'person' => m.mentor, 'institution' => m.mentor.institution } } @mentorships.push(@mentorships_obj) end return @mentorships end |
+ (Object) mentorship_notifications
finds all unapproved mentorships between approved people reflects mentorships between existing people
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'app/lib/notifier.rb', line 79 def self.mentorship_notifications @unapproved_mentorships = Mentorship.where({:approved => false}) .includes(:institution) .includes(person: :institution) .includes(mentor: :institution) @res_array = Array.new @unapproved_mentorships.each do |m| if m.person.approved and m.mentor.approved @mentorship = { 'mentorship' => { 'data' => m, 'institution' => m.institution }, 'mentored' => { 'person' => m.person, 'institution' => m.person.institution }, 'mentor' => { 'person' => m.mentor, 'institution' => m.mentor.institution } } @res_array.push(@mentorship) end end return @res_array end |
+ (Object) person_notifications
this method will bundle all relationships + information w.r.t. an unapproved person. This reflects a person that was just added to the database. TODO: refactor and fold with Search.person_info
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/lib/notifier.rb', line 110 def self.person_notifications # person, their mentors and their supervisors @unapproved_people = Person.where({:approved => false}) .includes(:institution) .includes(mentorships: [:institution, {mentor: [:institution]}]) .includes( {supervisions: [ {degree: [:institution] }, {supervisor: [:institution]}] }) # supervisions person was involved in, ie, they were the supervisor @unapproved_supervisions = Supervision.where({:approved => false, :supervisor_id => @unapproved_people.ids}) .includes(degree: :institution) .includes(person: :institution) # mentorships person was involved in, ie, they were the mentor @unapproved_mentorships = Mentorship.where({:approved => false, :mentor_id => @unapproved_people.ids}) .includes(:institution) .includes(person: :institution) @res_array = Array.new @unapproved_people.each do |p| @target = {'person' => p, 'person_institution' => p.institution} # got the supervisor, supervision, degree + institutions @supervisors = self.supervisors(p.supervisions) # got the mentors, mentorships + institutions @mentors = self.mentors(p.mentorships) # get the person's supervisions, supervised, degrees + instituitons # suffix raw implies that the data still needs to be processed into a more # friendly form. @supervised_raw = @unapproved_supervisions.where(:supervisor_id => p.id) .includes(degree: :institution) .includes(person: :institution) @supervised = self.supervised(@supervised_raw) @mentored_raw = @unapproved_mentorships.where(:mentor_id => p.id) .includes(:institution) .includes(person: :institution) @mentored = self.mentored(@mentored_raw) @aggregated_person = { 'target' => @target, 'mentors' => @mentors, 'mentored' => @mentored, 'supervised' => @supervised, 'supervisors' => @supervisors } @res_array.push(@aggregated_person) end return @res_array end |
+ (Object) supervised(unapproved_supervisions)
helper method used to build supervisions for unapproved person where the person was the supervisor
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'app/lib/notifier.rb', line 223 def self.supervised(unapproved_supervisions) @supervisions = Array.new unapproved_supervisions.each do |s| @supervision_obj = { 'supervision' => s, 'degree' => { 'degree' => s.degree, 'institution' => s.degree.institution }, 'supervised' => { 'person' => s.person, 'institution' => s.person.institution } } @supervisions.push(@supervision_obj) end return @supervisions end |
+ (Object) supervision_notifications
return supervision_notifications for approved people this reflects a relationship between existing people
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/lib/notifier.rb', line 47 def self.supervision_notifications @unapproved_supervisions = Supervision.where({:approved => false}) .includes(degree: :institution) .includes(person: :institution) .includes(supervisor: :institution) @res_array = Array.new @unapproved_supervisions.each do |s| if s.person.approved and s.supervisor.approved @supervision = { 'supervision' => { 'data' => s, 'degree' => s.degree, 'institution' => s.degree.institution }, 'supervised' => { 'person' => s.person, 'institution' => s.person.institution }, 'supervisor' => { 'person' => s.supervisor, 'institution' => s.supervisor.institution } } @res_array.push(@supervision) end end return @res_array end |
+ (Object) supervisors(unapproved_supervisions)
helper method for building the person notification where they were supervised
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/lib/notifier.rb', line 166 def self.supervisors(unapproved_supervisions) @supervisions = Array.new unapproved_supervisions.each do |s| @supervision_obj = { 'supervision' => s, 'degree' => { 'degree' => s.degree, 'institution' => s.degree.institution }, 'supervisor' => { 'person' => s.supervisor, 'institution' => s.supervisor.institution } } @supervisions.push(@supervision_obj) end return @supervisions end |
+ (Object) user_notifications
finds all unapproved users
17 18 19 20 21 22 23 24 25 |
# File 'app/lib/notifier.rb', line 17 def self.user_notifications @unapproved_users = User.where({:approved => false}) @res_array = Array.new @unapproved_users.each do |u| @res_array.push(u) end return @res_array end |