Class: Pundit::PolicyFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/pundit/policy_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ PolicyFinder

Returns a new instance of PolicyFinder.



5
6
7
# File 'lib/pundit/policy_finder.rb', line 5

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



3
4
5
# File 'lib/pundit/policy_finder.rb', line 3

def object
  @object
end

Instance Method Details

#policyObject



15
16
17
18
19
20
21
# 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!Object



27
28
29
# File 'lib/pundit/policy_finder.rb', line 27

def policy!
  policy or raise NotDefinedError, "unable to find policy #{find} for #{object}"
end

#scopeObject



9
10
11
12
13
# File 'lib/pundit/policy_finder.rb', line 9

def scope
  policy::Scope if policy
rescue NameError
  nil
end

#scope!Object



23
24
25
# File 'lib/pundit/policy_finder.rb', line 23

def scope!
  scope or raise NotDefinedError, "unable to find scope #{find}::Scope for #{object}"
end