Class: Pundit::PolicyFinder
- Inherits:
-
Object
- Object
- Pundit::PolicyFinder
- Defined in:
- lib/pundit/policy_finder.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object) ⇒ PolicyFinder
constructor
A new instance of PolicyFinder.
- #policy ⇒ Object
- #policy! ⇒ Object
- #scope ⇒ Object
- #scope! ⇒ Object
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
#object ⇒ Object (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
#policy ⇒ Object
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
28 29 30 31 |
# File 'lib/pundit/policy_finder.rb', line 28 def policy! raise NotDefinedError, "unable to find policy of nil" if object.nil? policy or raise NotDefinedError, "unable to find policy `#{find}` for `#{object.inspect}`" end |
#scope ⇒ Object
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 26 |
# File 'lib/pundit/policy_finder.rb', line 23 def scope! raise NotDefinedError, "unable to find policy scope of nil" if object.nil? scope or raise NotDefinedError, "unable to find scope `#{find}::Scope` for `#{object.inspect}`" end |