Methods
Instance Public methods
find_policy(role, resource, additional_class = nil)
Link
Looks for the policy associated with a role and resource
If a policy for a role and resource is not found, looks for the policy associated with the role.
Examples
find_policy(:author, Blog)
Source: show
# File rhino/rhino/app/helpers/rhino/policy_helper.rb 16 def find_policy(role, resource, additional_class = nil) 17 role = role.to_s if role.is_a? Symbol 18 role = role.classify 19 20 resource = resource.class if resource.class != Class 21 resource = resource.to_s.classify 22 23 policy_class = 'Policy' 24 policy_class = "#{policy_class}::#{additional_class}" if additional_class 25 26 # Look for role and resource specific policy 27 policy_constant = "#{role}#{resource}#{policy_class}".safe_constantize 28 return policy_constant if policy_constant.present? 29 30 # Fall back to just the role specific policy 31 policy_constant = "#{role}#{policy_class}".safe_constantize 32 return policy_constant if policy_constant.present? 33 34 # Fall back just to the rhino version 35 "Rhino::#{role}#{policy_class}".safe_constantize 36 end