Module: DeclarativePolicy::Cache

Defined in:
lib/declarative_policy/cache.rb

Class Method Summary collapse

Class Method Details

.policy_key(user, subject) ⇒ Object



12
13
14
15
16
# 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) ⇒ Object



18
19
20
21
22
23
# 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) ⇒ Object



6
7
8
9
10
# File 'lib/declarative_policy/cache.rb', line 6

def user_key(user)
  return '<anonymous>' if user.nil?

  "#{user.class.name}:#{id_for(user)}"
end