You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

analysis.rb 768B

123456789101112131415161718192021222324252627282930313233343536
  1. class Analysis < ApplicationRecord
  2. enum service: %i[https smtp xmpp tls ssh].collect { |e| [e, e.to_s] }.to_h
  3. validates :service, presence: true
  4. validates :host, presence: true
  5. def self.[](service, host, port)
  6. key = self.key service, host, port
  7. self.find_by key
  8. end
  9. def self.pending!(service, host, port)
  10. key = self.key service, host, port
  11. analysis = self.find_or_create_by! key
  12. analysis.pending!
  13. end
  14. def pending!
  15. self.update! pending: true
  16. self
  17. end
  18. def self.post!(service, host, port, result)
  19. analysis = self[service, host, port]
  20. analysis.post! result
  21. end
  22. def post!(result)
  23. self.update! pending: false, result: result
  24. end
  25. private
  26. def self.key(service, host, port)
  27. { service: service, host: host, port: port }
  28. end
  29. end