class Pundit::PolicyFinder
Attributes
object[R]
Public Class Methods
new(object)
click to toggle source
# File lib/pundit/policy_finder.rb, line 5 def initialize(object) @object = object end
Public Instance Methods
policy()
click to toggle source
# File lib/pundit/policy_finder.rb, line 15 def policy klass = find klass = klass.constantize if klass.is_a?(String) klass rescue NameError nil end
policy!()
click to toggle source
# File lib/pundit/policy_finder.rb, line 27 def policy! policy or raise NotDefinedError, "unable to find policy #{find} for #{object}" end
scope()
click to toggle source
# File lib/pundit/policy_finder.rb, line 9 def scope policy::Scope if policy rescue NameError nil end
scope!()
click to toggle source
# File lib/pundit/policy_finder.rb, line 23 def scope! scope or raise NotDefinedError, "unable to find scope #{find}::Scope for #{object}" end
Private Instance Methods
find()
click to toggle source
# File lib/pundit/policy_finder.rb, line 33 def find if object.respond_to?(:policy_class) object.policy_class elsif object.class.respond_to?(:policy_class) object.class.policy_class else klass = if object.respond_to?(:model_name) object.model_name elsif object.class.respond_to?(:model_name) object.class.model_name elsif object.is_a?(Class) object else object.class end "#{klass}Policy" end end