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.

49 lines
824B

  1. module CryptCheck
  2. module Statused
  3. def status
  4. @status ||= calculate_status
  5. end
  6. private
  7. def merge(statuses)
  8. Status.collect do |s|
  9. status = statuses.collect { |ss| ss[s] }
  10. status = status.inject &:+
  11. [s, status.uniq]
  12. end.to_h
  13. end
  14. def checks
  15. []
  16. end
  17. def children
  18. []
  19. end
  20. def perform_check(check)
  21. name, check, level = check
  22. result = check.call self
  23. return nil unless result
  24. level ||= result
  25. [level, name]
  26. end
  27. def personal_status
  28. states = Status.empty
  29. checks.each do |check|
  30. level, name = perform_check check
  31. next unless level
  32. states[level] << name
  33. end
  34. states
  35. end
  36. def calculate_status
  37. children_statuses = children.collect(&:status)
  38. statuses = [personal_status] + children_statuses
  39. merge statuses
  40. end
  41. end
  42. end