module Notifly::Models::Flyable
Public Instance Methods
_create_notification_for(fly)
click to toggle source
# File lib/notifly/models/flyable.rb, line 92 def _create_notification_for(fly) new_fly = _default_fly.merge(fly) notification = Notifly::Notification.create _get_attributes_from(new_fly) _after_create_notification(notification, new_fly) rescue => e logger.error "Something goes wrong with Notifly, will ignore: #{e}" raise e if not Rails.env.production? end
notifly_notifications(kind=nil)
click to toggle source
# File lib/notifly/models/flyable.rb, line 104 def notifly_notifications(kind=nil) notifications = Notifly::Notification.all_from(self) kind.present? ? notifications.where(kind: kind) : notifications end
Private Instance Methods
_after_create_notification(notification, fly)
click to toggle source
# File lib/notifly/models/flyable.rb, line 138 def _after_create_notification(notification, fly) if fly.then.present? block = fly.then; block.parameters.present? ? instance_exec(notification, &block) : instance_exec(&block) end if fly.mail.present? template = fly.mail.try(:fetch, :template) || notification.template Notifly::NotificationMailer.notifly to: instance_eval(fly.receiver.to_s).email, template: template, notification_id: notification.id end end
_default_fly()
click to toggle source
# File lib/notifly/models/flyable.rb, line 110 def _default_fly self.class.default_fly || Notifly::Models::Options::Fly.new end
_eval_for(key, value)
click to toggle source
# File lib/notifly/models/flyable.rb, line 124 def _eval_for(key, value) if [:template, :mail, :kind].include? key.to_sym value elsif value == :self self else if value.is_a? Proc instance_exec &value else send(value) end end end
_get_attributes_from(fly)
click to toggle source
# File lib/notifly/models/flyable.rb, line 114 def _get_attributes_from(fly) evaluated_attributes = {} fly.attributes.each do |key, value| evaluated_attributes[key] = _eval_for(key, value) end evaluated_attributes end