class Noticent::ActiveRecordOptInProvider
should be used only for testing
Public Instance Methods
add_alert(scope:, alert_name:, recipient_ids:, channel:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 18 def add_alert(scope:, alert_name:, recipient_ids:, channel:) ActiveRecord::Base.transaction do now = Time.now.utc.to_s(:db) # fetch all permutations of recipient and entity id permutations = Noticent::OptIn.distinct .where('recipient_id IN (?)', recipient_ids) .pluck(:entity_id, :recipient_id) return if permutations.empty? values = permutations.map { |e, r| "('#{scope}','#{alert_name}', #{e}, #{r}, '#{channel}', '#{now}', '#{now}')" }.join(',') ActiveRecord::Base.connection.execute("INSERT INTO opt_ins (scope, alert_name, entity_id, recipient_id, channel_name, created_at, updated_at) VALUES #{values}") end end
opt_in(recipient_id:, scope:, entity_id:, alert_name:, channel_name:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 6 def opt_in(recipient_id:, scope:, entity_id:, alert_name:, channel_name:) Noticent::OptIn.create!(recipient_id: recipient_id, scope: scope, entity_id: entity_id, alert_name: alert_name, channel_name: channel_name) end
opt_out(recipient_id:, scope:, entity_id:, alert_name:, channel_name:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 10 def opt_out(recipient_id:, scope:, entity_id:, alert_name:, channel_name:) Noticent::OptIn.where(recipient_id: recipient_id, scope: scope, entity_id: entity_id, alert_name: alert_name, channel_name: channel_name).destroy_all end
opted_in?(recipient_id:, scope:, entity_id:, alert_name:, channel_name:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 14 def opted_in?(recipient_id:, scope:, entity_id:, alert_name:, channel_name:) Noticent::OptIn.where(recipient_id: recipient_id, scope: scope, entity_id: entity_id, alert_name: alert_name, channel_name: channel_name).count != 0 end
remove_alert(scope:, alert_name:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 33 def remove_alert(scope:, alert_name:) Noticent::OptIn.where('scope = ? AND alert_name = ?', scope, alert_name).destroy_all end
remove_entity(scope:, entity_id:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 37 def remove_entity(scope:, entity_id:) Noticent::OptIn.where('scope = ? AND entity_id = ?', scope, entity_id).destroy_all end
remove_recipient(recipient_id:)
click to toggle source
# File lib/noticent/active_record_opt_in_provider.rb, line 41 def remove_recipient(recipient_id:) Noticent::OptIn.where(recipient_id: recipient_id).destroy_all end