summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhttp://jneen.net/ <jneen@jneen.net>2017-07-17 10:43:55 -0700
committerhttp://jneen.net/ <jneen@jneen.net>2017-07-17 14:38:48 -0700
commit45e9d2879122d2aea9494241fac0bd8bf7096446 (patch)
treefb17d477248c53ab1c9b55c005f81478d5bfdf96
parente515aa548cbc35d71cfc16a8b5d4abf5dd7d91bd (diff)
downloadgitlab-ce-45e9d2879122d2aea9494241fac0bd8bf7096446.tar.gz
avoid #respond_to? in Cache.id_for
-rw-r--r--lib/declarative_policy/cache.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/declarative_policy/cache.rb b/lib/declarative_policy/cache.rb
index b8cc60074c7..0804edba016 100644
--- a/lib/declarative_policy/cache.rb
+++ b/lib/declarative_policy/cache.rb
@@ -21,11 +21,14 @@ module DeclarativePolicy
private
def id_for(obj)
- if obj.respond_to?(:id) && obj.id
- obj.id.to_s
- else
- "##{obj.object_id}"
- end
+ id =
+ begin
+ obj.id
+ rescue NoMethodError
+ nil
+ end
+
+ id || "##{obj.object_id}"
end
end
end