Guest User

Untitled

a guest
Apr 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. class AuditReporter
  2. include ActionView::Helpers::UrlHelper
  3.  
  4. def initialize(audit, template)
  5. @audit = audit
  6. @auditable = audit.auditable
  7. @template = template
  8. end
  9.  
  10. def report
  11. method = "#{@audit.kind}_#{@audit.auditable_type.downcase}"
  12. send(method)
  13. end
  14.  
  15. def method_missing(*args, &block)
  16. "A #{@audit.kind} event occurred on #{@audit.auditable_type} #{@audit.auditable_id}."
  17. end
  18.  
  19. private
  20.  
  21. def create_profile
  22. "A new profile, #{profile_link(@auditable)}, was added."
  23. end
  24.  
  25. def create_artifacttemplate
  26. "A new template, #{template_link(@auditable)}, was added to profile, #{profile_link(@auditable.profile)}."
  27. end
  28.  
  29. def create_artifact
  30. "A new artifact, #{artifact_link(@auditable)}, was added to template, #{profile_link(@auditable.artifact_template)}."
  31. end
  32.  
  33. def create_artifactversion
  34. "A new version (##{@auditable.my_version}) was discovered for artifact, #{artifact_link(@auditable.artifact)}."
  35. end
  36.  
  37. def profile_link(profile)
  38. url = @template.send(:profile_url, profile)
  39. link_to profile.name, url
  40. end
  41.  
  42. def template_link(template)
  43. url = @template.send(:profile_template_url, template.profile, template)
  44. link_to template.name, url
  45. end
  46.  
  47. def artifact_link(artifact)
  48. url = @template.send(:profile_template_artifact_url, artifact.artifact_template.profile, artifact.artifact_template, artifact)
  49. link_to artifact.name, url
  50. end
  51.  
  52. end
Add Comment
Please, Sign In to add comment