Module: Copper::Permission
- Included in:
- Permission
- Defined in:
- lib/copper/permission.rb
Defined Under Namespace
Classes: Naming
Instance Method Summary collapse
-
#apply_to(ability) ⇒ Object
Apply this permission to the ability, directly via cancan or via the Policy object if one is available.
-
#has_action_policy? ⇒ Boolean
True if there is a Policy class specific to the action available to complement the permission.
-
#has_type_policy? ⇒ Boolean
True if there is a Policy class for the type available to complement the permission.
-
#policy_action_class ⇒ Object
The Policy class for the specific action if one is present.
-
#policy_type_class ⇒ Object
The Policy class for the type if one is present (Only used if there is no specific action class).
Instance Method Details
#apply_to(ability) ⇒ Object
Apply this permission to the ability, directly via cancan or via the Policy object if one is available
39 40 41 42 43 44 45 46 47 |
# File 'lib/copper/permission.rb', line 39 def apply_to(ability) if has_action_policy? policy_action_class.new(ability).apply! elsif has_type_policy? policy_type_class.new(ability).apply! else ability.can(action_name.to_sym, object_type.constantize) end end |
#has_action_policy? ⇒ Boolean
Returns true if there is a Policy class specific to the action available to complement the permission.
14 15 16 |
# File 'lib/copper/permission.rb', line 14 def has_action_policy? self.class.const_defined?(Naming.action_class_name(object_type, action_name)) end |
#has_type_policy? ⇒ Boolean
Returns true if there is a Policy class for the type available to complement the permission.
19 20 21 |
# File 'lib/copper/permission.rb', line 19 def has_type_policy? self.class.const_defined?(Naming.class_name(object_type)) end |
#policy_action_class ⇒ Object
The Policy class for the specific action if one is present
25 26 27 |
# File 'lib/copper/permission.rb', line 25 def policy_action_class Naming.action_class_name(object_type, action_name).constantize end |
#policy_type_class ⇒ Object
The Policy class for the type if one is present (Only used if there is no specific action class)
32 33 34 |
# File 'lib/copper/permission.rb', line 32 def policy_type_class Naming.class_name(object_type).constantize end |