module DeclarativePolicy::Cache

Public Class Methods

policy_key(user, subject) click to toggle source
# File lib/declarative_policy/cache.rb, line 12
def policy_key(user, subject)
  u = user_key(user)
  s = subject_key(subject)
  "/dp/policy/#{u}/#{s}"
end
subject_key(subject) click to toggle source
# File lib/declarative_policy/cache.rb, line 18
def subject_key(subject)
  return '<nil>' if subject.nil?
  return subject.inspect if subject.is_a?(Symbol)

  "#{subject.class.name}:#{id_for(subject)}"
end
user_key(user) click to toggle source
# File lib/declarative_policy/cache.rb, line 6
def user_key(user)
  return '<anonymous>' if user.nil?

  id_for(user)
end

Private Class Methods

id_for(obj) click to toggle source
# File lib/declarative_policy/cache.rb, line 27
def id_for(obj)
  id =
    begin
      obj.id
    rescue NoMethodError
      nil
    end

  id || "##{obj.object_id}"
end