1
0

status_finder.rb 616 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class StatusFinder
  3. attr_reader :url
  4. def initialize(url)
  5. @url = url
  6. end
  7. def status
  8. verify_action!
  9. raise ActiveRecord::RecordNotFound unless TagManager.instance.local_url?(url)
  10. case recognized_params[:controller]
  11. when 'statuses'
  12. Status.find(recognized_params[:id])
  13. else
  14. raise ActiveRecord::RecordNotFound
  15. end
  16. end
  17. private
  18. def recognized_params
  19. Rails.application.routes.recognize_path(url)
  20. end
  21. def verify_action!
  22. unless recognized_params[:action] == 'show'
  23. raise ActiveRecord::RecordNotFound
  24. end
  25. end
  26. end