diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-08 00:02:16 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-08-08 00:02:16 +0900 |
commit | a5fce8dfb8e13eceed7a9cec8698888f2c47d454 (patch) | |
tree | 409433a3a052c3c3bec7855b4c0e7be1068d848d /app/controllers/application_controller.rb | |
parent | 97c93f3c72ec45cded0c0b682e6c02933d08fa12 (diff) | |
download | aclog-a5fce8dfb8e13eceed7a9cec8698888f2c47d454.tar.gz |
web: controllers: extract loading specified user
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e2efb08..fe1f1a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,13 +30,19 @@ class ApplicationController < ActionController::Base end def authorize!(object) - if object.is_a? User - authorized_to_show_user?(object) || raise(Aclog::Exceptions::UserProtected, object) - elsif object.is_a? Tweet + case object + when User + unless authorized_to_show_user?(object) + raise(Aclog::Exceptions::UserProtected, object) + end + when Tweet authorize! object.user + when NilClass + raise Aclog::Exceptions::NotFound else raise ArgumentError, "parameter `object` must be a User or a Tweet" end + object end |