2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-08-14 10:05:53 -05:00
|
|
|
module ScreeningModel
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
def actions
|
2014-09-04 17:50:27 -05:00
|
|
|
@actions ||= Enum.new(:block, :do_nothing, :allow_admin)
|
2013-08-14 10:05:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def default_action(action_key)
|
|
|
|
@default_action = action_key
|
|
|
|
end
|
|
|
|
|
|
|
|
def df_action
|
|
|
|
@default_action || :do_nothing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
included { before_validation :set_default_action }
|
|
|
|
|
|
|
|
def set_default_action
|
|
|
|
self.action_type ||= self.class.actions[self.class.df_action]
|
|
|
|
end
|
|
|
|
|
2013-10-22 15:30:30 -05:00
|
|
|
def action_name=(arg)
|
|
|
|
if arg.nil? || !self.class.actions.has_key?(arg.to_sym)
|
|
|
|
raise ArgumentError.new("Invalid action type #{arg}")
|
2023-01-09 06:10:19 -06:00
|
|
|
end
|
2013-10-22 15:30:30 -05:00
|
|
|
self.action_type = self.class.actions[arg.to_sym]
|
|
|
|
end
|
|
|
|
|
2013-08-14 10:05:53 -05:00
|
|
|
def record_match!
|
|
|
|
self.match_count += 1
|
|
|
|
self.last_match_at = Time.zone.now
|
|
|
|
save
|
|
|
|
end
|
|
|
|
end
|