How to use included method of InstanceMethods Package

Best Spinach_ruby code snippet using InstanceMethods.included

notifications.rb

Source:notifications.rb Github

copy

Full Screen

...8 SENDING_BATCH_SIZE = 509 #SMTP SERVER10 SMTP_SERVER = Config[:smtp_settings][:address]11 12 # included do13 # 14 # end15 16 17 module InstanceMethods18 end19 20 module ClassMethods21 def send_batch_email(tmail_object, whom=[])22 return if whom.blank?23 tmail = tmail_object24 recipients = whom25 exceptions = {}26 recipients.each_slice(SENDING_BATCH_SIZE) do |recipients_slice|27 Net::SMTP.start(SMTP_SERVER, 25) do |sender|28 recipients_slice.each do |recipient|29 tmail.to = recipient30 begin31 sender.sendmail tmail.encoded, tmail.from, recipient32 rescue Exception => e33 exceptions[recipient] = e 34 #needed as the next mail will send command MAIL FROM, which would 35 #raise a 503 error: "Sender already given"36 sender.finish37 sender.start38 end39 end40 end41 end42 end43 44 end45 end46 47 48 module Profile49 extend ActiveSupport::Concern50 51 included do52 self.after_save :fire_notifications53 end54 55 # def included(base)56 # base.send :include, InstanceMethods57 # base.extend ClassMethods58 # end 59 60 module InstanceMethods61 def fire_notifications62 Notifier.deliver_welcome(self.user) if self.should_receive_welcome_email?63 end64 65 def should_receive_welcome_email?66 if self.user.srw_agent_id.to_i != 067 # Sabre Red User -- They get Sabre Red Welcome email -- see user68 false69 elsif self.id_was.nil? && (self.status == 2 || self.status == 1) 70 # Admin Created Users -- manually created or bulk uploaded71 true72 else73 # if the user is active, but has never logged in does not use SSO and had a status <= 074 # i.e. change a user from pending to active or activate_on_login75 self.new_user? && self.status_was.to_i <= 076 end 77 end78 end79 80 module ClassMethods81 # class methods here82 end83 end 84 85 module User86 extend ActiveSupport::Concern87 88 included do89 self.after_save :fire_notifications90 end91 92 module InstanceMethods93 def fire_notifications94 Notifier.deliver_sabre_red_sso_welcome(self) if self.should_receive_sabre_red_welcome_email?95 end96 97 def should_receive_sabre_red_welcome_email?98 # this is in the User, not profile because _was did not return correct value when referenced by something other than self99 self.srw_agent_id.to_i != 0 && self.terms_accepted && !self.terms_accepted_was100 end101 end102 103 module ClassMethods104 # class methods here105 end106 end 107 108 module BlogPost109 extend ActiveSupport::Concern110 111 included do112 self.after_create :fire_notifications113 self.send :include, Notifications::BatchMailer114 end115 116 117 module InstanceMethods118 def fire_notifications 119 if self.company?120 self.class.delay.send_company_blog_post(self.id)121 elsif self.group?122 self.class.delay.send_group_blog_post(self.id)123 elsif self.news?124 self.class.delay.send_news_blog_post(self.id)125 else126 # don't send emails for profile blogs :)127 end 128 end129 end130 131 module ClassMethods132 # class methods here133 end134 end135 136 module Question137 extend ActiveSupport::Concern138 139 included do140 self.after_save :fire_notifications141 end142 143 144 module InstanceMethods145 def fire_notifications 146 SemanticMatcher.default.match_question_to_profiles(self)147 Notifier.delay.send_question_match_notifications(self.id) 148 end149 end150 end151 152 module Answer153 extend ActiveSupport::Concern154 155 included do156 self.after_save :fire_notifications157 self.after_update :fire_update_notifications158 end159 160 161 module InstanceMethods162 def fire_notifications 163 Notifier.deliver_answer_to_question(self) if self.question.per_answer_notification164 Notifier.deliver_watched_question_answer(self) unless self.question.watchers.collect {|watcher| watcher.email if watcher.watched_question_answer_email_status==1 }.compact.empty?165 end166 167 def fire_update_notifications168 q = ::Question.unscoped.find_by_id(self.question_id)169 Notifier.deliver_best_answer(self) if self.best_answer and self.attribute_modified?(:best_answer) and q.is_closed?170 end171 end172 end173 174 module Abuse175 extend ActiveSupport::Concern176 177 included do178 self.after_save :fire_notifications179 self.send :include, Notifications::BatchMailer180 end181 182 module InstanceMethods183 def fire_notifications184 send_new_abuse_email 185 end186 187 def send_new_abuse_email188 recipients = ::Profile.include_shady_admins.collect { |admin| admin.email }189 tmail = Notifier.new_abuse190 self.class.send_batch_email(tmail, recipients)191 end 192 end193 end194 195 module Group196 extend ActiveSupport::Concern197 198 included do199 self.after_update :fire_update_notifications200 end201 202 module InstanceMethods203 def fire_update_notifications204 Notifier.deliver_group_owner(self) if self.attribute_modified?(:owner_id) 205 end206 end 207 end208 209 module GroupMembership210 extend ActiveSupport::Concern211 212 included do213 self.after_update :fire_update_notifications214 end215 216 module InstanceMethods217 def fire_update_notifications218 not_owner = self.profile_id!=self.group.owner_id219 Notifier.deliver_group_moderator(self) if self.moderator and not_owner and self.attribute_modified?(:moderator)220 end 221 end 222 end 223 224 module GroupInvitation225 extend ActiveSupport::Concern226 227 included do228 self.after_save :fire_notifications229 self.after_update :fire_update_notifications230 end231 232 module InstanceMethods233 def fire_notifications234 Notifier.deliver_group_invitation(self) if self.receiver.group_invitation_email_status235 end236 237 def fire_update_notifications238 Notifier.deliver_group_invitation(self) if self.receiver.group_invitation_email_status239 end 240 end 241 end242 243 module GroupInvitationRequest244 extend ActiveSupport::Concern245 246 included do247 self.after_create :fire_notifications248 end249 250 module InstanceMethods251 def fire_notifications252 Notifier.deliver_group_invitation_request(self)253 end254 255 end 256 end257 258 module GroupPost259 extend ActiveSupport::Concern260 261 included do262 self.after_save :fire_notifications263 end264 265 module InstanceMethods266 def fire_notifications267 self.delay.send_group_post268 end269 end 270 end271 272 module ProfileAward273 extend ActiveSupport::Concern274 275 included do276 self.after_save :fire_notifications277 end278 279 module InstanceMethods280 def fire_notifications281 Notifier.deliver_profile_award(self)282 end283 end 284 end285 286 module Reply287 extend ActiveSupport::Concern288 289 included do290 self.after_save :fire_notifications291 end292 293 module InstanceMethods294 def fire_notifications295 Notifier.deliver_reply(self) if self.answer.profile.new_reply_on_answer_notification296 end297 end 298 end299 300 module GetthereBooking301 extend ActiveSupport::Concern302 303 included do304 self.after_save :fire_notifications305 end306 307 module InstanceMethods308 def fire_notifications309 Notifiers::Travel.deliver_new_getthere_booking(self) if self.profile.travel_email_status && !self.past?310 end311 end 312 end313 314 module Comment315 extend ActiveSupport::Concern316 317 included do318 self.after_save :fire_notifications319 end320 321 module InstanceMethods322 def fire_notifications323 if self.belongs_to_group_blog_post? 324 Notifier.deliver_new_comment_on_group_blog_post(self)325 elsif self.belongs_to_group_post?326 Notifiers::Group.deliver_new_comment_on_group_post(self)327 elsif self.company?328 Notifier.deliver_new_comment_on_company_blog_post(self)329 else330 if self.root_parent_profile? && self.owner.root_parent.new_comment_on_blog_notification 331 Notifier.deliver_new_comment_on_blog(self)332 end 333 end334 end335 end 336 end337 338 module Note339 extend ActiveSupport::Concern340 341 included do342 self.after_save :fire_notifications343 end344 345 module InstanceMethods346 def fire_notifications347 if self.receiver.is_a?(Group)348 self.delay.send_group_note349 else350 Notifier.deliver_note(self) if self.receiver.note_email_status==1351 end352 end353 end 354 end355 module QuestionReferral356 extend ActiveSupport::Concern357 358 included do359 self.after_save :fire_notifications360 self.send :include, Notifications::BatchMailer361 end362 363 module InstanceMethods364 def fire_notifications365 if self.owner.is_a?(Group)366 delay.send_group_referral_email367 end368 end369 370 def send_group_referral_email371 tmail = Notifier.group_referral(self)372 recipients = self.group.members.collect {|p| p.email }...

Full Screen

Full Screen

model.rb

Source:model.rb Github

copy

Full Screen

1module Virtus2 module Model3 # @api private4 def self.included(descendant)5 super6 descendant.send(:include, ClassInclusions)7 end8 # @api private9 def self.extended(descendant)10 super11 descendant.extend(Extensions)12 end13 module Core14 # @api private15 def self.included(descendant)16 super17 descendant.extend(ClassMethods)18 descendant.send(:include, ClassInclusions::Methods)19 descendant.send(:include, InstanceMethods)20 end21 private_class_method :included22 # @api private23 def self.extended(descendant)24 super25 descendant.extend(Extensions::Methods)26 descendant.extend(InstanceMethods)27 end28 private_class_method :included29 end # Core30 module Constructor31 # @api private32 def self.included(descendant)33 super34 descendant.send(:include, InstanceMethods::Constructor)35 end36 private_class_method :included37 end # Constructor38 module MassAssignment39 # @api private40 def self.included(descendant)41 super42 descendant.extend(Extensions::AllowedWriterMethods)43 descendant.send(:include, InstanceMethods::MassAssignment)44 end45 private_class_method :included46 # @api private47 def self.extended(descendant)48 super49 descendant.extend(Extensions::AllowedWriterMethods)50 descendant.extend(InstanceMethods::MassAssignment)51 end52 private_class_method :extended53 end # MassAssignment54 end # Model55end # Virtus...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Spinach_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful