Class: Decidim::SpamDetection::SpamUserCommandAdapter
- Inherits:
-
Object
- Object
- Decidim::SpamDetection::SpamUserCommandAdapter
- Includes:
- Command
- Defined in:
- lib/decidim/spam_detection/spam_user_command_adapter.rb
Constant Summary collapse
- SPAM_LEVEL =
{ very_sure: 0.99, probable: 0.7 }.freeze
Instance Attribute Summary
Attributes included from Command
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(probability_hash) ⇒ SpamUserCommandAdapter
constructor
A new instance of SpamUserCommandAdapter.
Methods included from Command
#errors, #failure?, prepended, #success?
Constructor Details
#initialize(probability_hash) ⇒ SpamUserCommandAdapter
Returns a new instance of SpamUserCommandAdapter.
13 14 15 16 |
# File 'lib/decidim/spam_detection/spam_user_command_adapter.rb', line 13 def initialize(probability_hash) @probability = probability_hash["spam_probability"] @user = probability_hash["original_user"] end |
Class Method Details
.perform_block_user? ⇒ Boolean
9 10 11 |
# File 'lib/decidim/spam_detection/spam_user_command_adapter.rb', line 9 def self.perform_block_user? Decidim::SpamDetection.spam_detection_api_perform_block_user end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/decidim/spam_detection/spam_user_command_adapter.rb', line 18 def call if @probability > SPAM_LEVEL[:very_sure] && self.class.perform_block_user? Decidim::SpamDetection::BlockSpamUserCommand.call(@user, @probability) :blocked_user elsif @probability > SPAM_LEVEL[:probable] Decidim::SpamDetection::ReportSpamUserCommand.call(@user, @probability) :reported_user else :nothing end end |