Class: Spree::Ability
- Inherits:
-
Object
- Object
- Spree::Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/spree/ability.rb
Class Method Summary collapse
-
.register_ability(ability) ⇒ Object
Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to modify the default
Ability
of an application. - .remove_ability(ability) ⇒ Object
Instance Method Summary collapse
-
#initialize(user) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user) ⇒ Ability
Returns a new instance of Ability.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/spree/ability.rb', line 26 def initialize(user) alias_cancan_delete_action user ||= Spree.user_class.new if user.persisted? && user.try(:spree_admin?) (user) else (user) end # Include any abilities registered by extensions, etc. # this is legacy behaviour and should be removed in Spree 5.0 Ability.abilities.merge(abilities_to_register).each do |clazz| merge clazz.new(user) end protect_admin_role end |
Class Method Details
.register_ability(ability) ⇒ Object
Allows us to go beyond the standard cancan initialize method which makes it difficult for engines to modify the default Ability
of an application. The ability
argument must be a class that includes the CanCan::Ability
module. The registered ability should behave properly as a stand-alone class and therefore should be easy to test in isolation.
18 19 20 |
# File 'app/models/spree/ability.rb', line 18 def self.register_ability(ability) abilities.add(ability) end |
.remove_ability(ability) ⇒ Object
22 23 24 |
# File 'app/models/spree/ability.rb', line 22 def self.remove_ability(ability) abilities.delete(ability) end |