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