diff options
author | http://jneen.net/ <jneen@jneen.net> | 2017-08-01 10:42:54 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2017-08-03 09:07:18 -0700 |
commit | c2dd4239c939e003dfe569196ec2d39e2478606e (patch) | |
tree | 05fa09b5d0f6324add395e5c5bf768c619d308a8 /lib/declarative_policy.rb | |
parent | 488e8e79dd85e973e1b562fe0320f69b2bedec06 (diff) | |
download | gitlab-ce-c2dd4239c939e003dfe569196ec2d39e2478606e.tar.gz |
short-circuit if there is no policy, and add :read_project check
Diffstat (limited to 'lib/declarative_policy.rb')
-rw-r--r-- | lib/declarative_policy.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/declarative_policy.rb b/lib/declarative_policy.rb index b1eb1a6cef1..4936669a73a 100644 --- a/lib/declarative_policy.rb +++ b/lib/declarative_policy.rb @@ -28,7 +28,12 @@ module DeclarativePolicy subject = find_delegate(subject) - class_for_class(subject.class) + class_for_class(subject.class) \ + or raise "no policy for #{subject.class.name}" + end + + def has_policy?(subject) + !class_for_class(subject.class).nil? end private @@ -51,9 +56,7 @@ module DeclarativePolicy end end - policy_class = subject_class.instance_variable_get(CLASS_CACHE_IVAR) - raise "no policy for #{subject.class.name}" if policy_class.nil? - policy_class + subject_class.instance_variable_get(CLASS_CACHE_IVAR) end def compute_class_for_class(subject_class) @@ -71,6 +74,8 @@ module DeclarativePolicy nil end end + + nil end def find_delegate(subject) |