2017-05-30 21:30:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 09:23:43 +01:00
|
|
|
class StatusFinder
|
2017-05-30 21:30:06 +01:00
|
|
|
attr_reader :url
|
|
|
|
|
|
|
|
def initialize(url)
|
|
|
|
@url = url
|
|
|
|
end
|
|
|
|
|
2017-08-30 09:23:43 +01:00
|
|
|
def status
|
2017-05-30 21:30:06 +01:00
|
|
|
verify_action!
|
|
|
|
|
|
|
|
case recognized_params[:controller]
|
|
|
|
when 'stream_entries'
|
2017-08-30 09:23:43 +01:00
|
|
|
StreamEntry.find(recognized_params[:id]).status
|
2017-05-30 21:30:06 +01:00
|
|
|
when 'statuses'
|
2017-08-30 09:23:43 +01:00
|
|
|
Status.find(recognized_params[:id])
|
2017-05-30 21:30:06 +01:00
|
|
|
else
|
|
|
|
raise ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def recognized_params
|
|
|
|
Rails.application.routes.recognize_path(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify_action!
|
|
|
|
unless recognized_params[:action] == 'show'
|
|
|
|
raise ActiveRecord::RecordNotFound
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|