Class: Regulator::PolicyFinder
- Inherits:
-
Object
- Object
- Regulator::PolicyFinder
- Defined in:
- lib/regulator/policy_finder.rb
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
-
#initialize(object, controller_or_namespace = nil) ⇒ PolicyFinder
constructor
A new instance of PolicyFinder.
- #policy ⇒ Object
- #policy! ⇒ Object
- #scope ⇒ Object
- #scope! ⇒ Object
Constructor Details
#initialize(object, controller_or_namespace = nil) ⇒ PolicyFinder
Returns a new instance of PolicyFinder.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/regulator/policy_finder.rb', line 7 def initialize(object, controller_or_namespace = nil) @object = object if controller_or_namespace.is_a?(Module) @namespace = controller_or_namespace elsif controller_or_namespace @controller = controller_or_namespace @namespace = @controller.policy_namespace end end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
4 5 6 |
# File 'lib/regulator/policy_finder.rb', line 4 def controller @controller end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
5 6 7 |
# File 'lib/regulator/policy_finder.rb', line 5 def namespace @namespace end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/regulator/policy_finder.rb', line 3 def object @object end |
Instance Method Details
#policy ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/regulator/policy_finder.rb', line 24 def policy klass = find klass = klass.constantize if klass.is_a?(String) klass rescue NameError nil end |
#policy! ⇒ Object
37 38 39 40 |
# File 'lib/regulator/policy_finder.rb', line 37 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
18 19 20 21 22 |
# File 'lib/regulator/policy_finder.rb', line 18 def scope policy::Scope if policy rescue NameError nil end |
#scope! ⇒ Object
32 33 34 35 |
# File 'lib/regulator/policy_finder.rb', line 32 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 |