class PasswordBreachAlert::BreachesFilters::AfterUserLastCheckedAt
returns the breaches with breach_date later then checked, then updates the date on user
Attributes
api[R]
field[R]
Public Class Methods
new(api: PasswordBreachAlert::Api::Breachedaccount.new, field: :password_breach_alert_checked_at)
click to toggle source
# File lib/password_breach_alert/breaches_filters/after_user_last_checked_at.rb, line 9 def initialize(api: PasswordBreachAlert::Api::Breachedaccount.new, field: :password_breach_alert_checked_at) @api = api @field = field end
Public Instance Methods
call(user, _new_breaches, breaches)
click to toggle source
# File lib/password_breach_alert/breaches_filters/after_user_last_checked_at.rb, line 14 def call(user, _new_breaches, breaches) unless user.respond_to?(field) raise NotImplementedError.new("please add the column of method #{field} to #{user.class}") end unless user[field].nil? || user[field].is_a?(Time) raise NotImplementedError.new("#{user.class}.#{field} should be a time") end api_breaches = api.call(user.email) api_breaches_names = api_breaches.map { |api_breach| api_breach['Name'] } scope = { name: api_breaches_names } scope[:breach_date] = user[field]..Time.current if user[field] user.update field => Time.current breaches.where(scope) end