Sha256: e73f636b9409652c7c42802e35a89fa23dd7f8c154e96bea87634f7cba8e010b
Contents?: true
Size: 995 Bytes
Versions: 5
Compression:
Stored size: 995 Bytes
Contents
module Notifiable class Batch attr_accessor :notifiers def initialize(config = {}) @notifiers = {} @config = config end def add(notification, user) user.device_tokens.each do |d| provider = d.provider.to_sym unless @notifiers[provider] clazz = Notifiable.notifier_classes[provider] raise "Notifier #{provider} not configured" unless clazz @notifiers[provider] = clazz.new @notifiers[provider].env = Rails.env @config[provider].each_pair {|key, value| @notifiers[provider].send("#{key}=", value) if @notifiers[provider].methods.include?("#{key}=".to_sym) } if @config[provider] end notifier = @notifiers[provider] if d.is_valid? && !notifier.nil? notifier.send_notification(notification, d) end end end def close @notifiers.each_value {|n| n.close} @notifiers = nil end end end
Version data entries
5 entries across 5 versions & 1 rubygems