Class: Spree::Ability
- Inherits:
-
Object
- Object
- Spree::Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/spree/ability.rb
Instance Attribute Summary collapse
-
#store ⇒ Spree::Store?
readonly
The current store.
-
#user ⇒ Object
readonly
The current user.
Class Method Summary collapse
-
.register_ability(ability) ⇒ Object
deprecated
Deprecated.
Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
-
.remove_ability(ability) ⇒ Object
deprecated
Deprecated.
Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
Instance Method Summary collapse
-
#initialize(user, options = {}) ⇒ Ability
constructor
A new instance of Ability.
Constructor Details
#initialize(user, options = {}) ⇒ Ability
Returns a new instance of Ability.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/spree/ability.rb', line 51 def initialize(user, = {}) alias_cancan_delete_action @user = user || Spree.user_class.new @store = [:store] || Spree::Current.store # 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| Spree::Deprecation.warn("Ability merging is deprecated and will be removed in Spree 5.5. Please use Permission Sets") merge clazz.new(@user) end end |
Instance Attribute Details
#store ⇒ Spree::Store? (readonly)
Returns the current store.
27 28 29 |
# File 'app/models/spree/ability.rb', line 27 def store @store end |
#user ⇒ Object (readonly)
Returns the current user.
24 25 26 |
# File 'app/models/spree/ability.rb', line 24 def user @user end |
Class Method Details
.register_ability(ability) ⇒ Object
Deprecated.
Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
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.
34 35 36 37 38 39 40 |
# File 'app/models/spree/ability.rb', line 34 def self.register_ability(ability) Spree::Deprecation.warn( 'Spree::Ability.register_ability is deprecated and will be removed in Spree 5.5. ' \ 'Please use Spree::PermissionSets instead. See Spree::PermissionSets::Base for details.' ) abilities.add(ability) end |
.remove_ability(ability) ⇒ Object
Deprecated.
Use Spree::PermissionSets instead. Will be removed in Spree 5.5.
43 44 45 46 47 48 49 |
# File 'app/models/spree/ability.rb', line 43 def self.remove_ability(ability) Spree::Deprecation.warn( 'Spree::Ability.remove_ability is deprecated and will be removed in Spree 5.5. ' \ 'Please use Spree::PermissionSets instead. See Spree::PermissionSets::Base for details.' ) abilities.delete(ability) end |