闭社主体 forked from https://github.com/tootsuite/mastodon
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.

34 lines
630 B

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