class Console1984::CommandValidator::SuspiciousTermsValidation
Validates that the command doesn't include a term based on a configured list.
Public Class Methods
new(suspicious_terms)
click to toggle source
# File lib/console1984/command_validator/suspicious_terms_validation.rb, line 5 def initialize(suspicious_terms) @suspicious_terms = suspicious_terms end
Public Instance Methods
validate(parsed_command)
click to toggle source
Raises a Console1984::Errors::SuspiciousCommand if the term is referenced.
# File lib/console1984/command_validator/suspicious_terms_validation.rb, line 10 def validate(parsed_command) if contains_suspicious_term?(parsed_command) raise Console1984::Errors::SuspiciousCommandAttempted end end
Private Instance Methods
contains_suspicious_term?(parsed_command)
click to toggle source
# File lib/console1984/command_validator/suspicious_terms_validation.rb, line 17 def contains_suspicious_term?(parsed_command) @suspicious_terms.find do |term| parsed_command.raw_command.include?(term) end end