Class: Spree::Ability

Inherits:
Object
  • Object
show all
Includes:
CanCan::Ability
Defined in:
app/models/spree/ability.rb

Constant Summary collapse

CUSTOM_ALIASES_MAP =
{
  delete: :destroy,
  display: :read,
  new_action: :create,
  read: :show
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user) ⇒ Ability

Returns a new instance of Ability.



36
37
38
39
40
41
# File 'app/models/spree/ability.rb', line 36

def initialize(current_user)
  @user = current_user || Spree.user_class.new

  activate_permission_sets
  register_extension_abilities
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



15
16
17
# File 'app/models/spree/ability.rb', line 15

def user
  @user
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.



28
29
30
# File 'app/models/spree/ability.rb', line 28

def self.register_ability(ability)
  abilities.add(ability)
end

.remove_ability(ability) ⇒ Object



32
33
34
# File 'app/models/spree/ability.rb', line 32

def self.remove_ability(ability)
  abilities.delete(ability)
end

Instance Method Details

#can?(action, *args) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/spree/ability.rb', line 43

def can?(action, *args)
  super(normalize_action(action), *args)
end

#model_adapter(model_class, action) ⇒ Object



47
48
49
# File 'app/models/spree/ability.rb', line 47

def model_adapter(model_class, action)
  super(model_class, normalize_action(action))
end